Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

EDIT: completely non-functional edited version of script removed
(see below)
Last edited by akroma222 on Sat Nov 26, 2016 2:27 pm, edited 1 time in total.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

In the user scripting interface, you cannot remove an item from a surface except by destroying the item.
Yes, I have code for adding an item to the map. This is not code for removing an item from a surface. It's code for adding an item to the map. It won't help with your surface problem. Nothing will help with your surface problem.
Here is the original code in context, by the way, instead of a completely non-functional edited version.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Oh well. Guess I'll have to stay with removing the surface component.
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Even destroying the SurfaceComponent won't help. The item will remain tainted and cause a crash upon pickup (if you didn't re-create the SurfaceComponent) or very bad behaviour/possibly another crash upon loading the game (if you did). I repeat: In the user scripting interface, you cannot remove an item from a surface except by destroying the item.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

minmay wrote:Even destroying the SurfaceComponent won't help. The item will remain tainted and cause a crash upon pickup (if you didn't re-create the SurfaceComponent) or very bad behaviour/possibly another crash upon loading the game (if you did). I repeat: In the user scripting interface, you cannot remove an item from a surface except by destroying the item.
I am re-creating the component, and the item doesn't seem to cause any issues afterwards.
No crashes after loading and the item functions normally ¯\_(ツ)_/¯
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

It might not seem to cause any issues but the fact is that this leaves the ItemComponent in an incorrect state. The item will still be marked as if it is in the SurfaceComponent, but the SurfaceComponent will not contain the item.
Therefore:
- picking up the item will trigger the onRemoveItem hook of the SurfaceComponent
- the item will not be pushed correctly, pickup location will be restricted, etc.
- ...unless you save and reload the game

I suppose it's possible that adding it to another inventory immediately (surface, container, monster, champion) would clean this up, but I am not at all comfortable saying that, since I do not have the source code.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

The issue with triggering onRemove is fixed with not giving the component any connectors.
I've faced the pickup issue, and I fixed it by placing it inside the player inventory before it's on the map. Since it'll probably annoy the user, I made it go through a monster before being set the the mouse item. That fixed it.
Only issue I'm having right now is a crash caused by leaving full screen ('F') after the item was in a surface component, added to a monster, the monster killed, the item set as the cursor item, and the surface removed and re-added.
Image

It only happens in the editor though, so it'll just be a pain in the ass to test with.
EDIT: Also there's the part where people will be using that in the editor, so I should do something about it... eeeeeeeeeeeh
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I'm still confused by this dicussion...

So it is not a matter if I destroy an item from a surface by item_01:destroy() Right? (I do this a lot in my mod - all items will never be used in my dungeon anymore)

There is just a problem if I want to do something else with my item?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Thats the problem - I can't destroy the item because I need it.
Guess I could go with destroying the old item and creating a new one then modify it, but I don't know if it'll have any drastic effects on the game because that process will be repeated. A lot.

Minmay, will destroying the old item and creating a new one (the modify it to my desires) will affect the game in a bad way considering this will happen a lot?
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Destroying the item is fine. When an ItemComponent is destroyed, if it's inside a SurfaceComponent it will tell that SurfaceComponent that it was removed. On the other hand, if you destroy a SurfaceComponent, and it contains items, it won't tell the items that they aren't in the (now nonexistent) surface anymore, which is why this problem appears.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply