Page 169 of 400

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 7:11 pm
by akroma222
EDIT: completely non-functional edited version of script removed
(see below)

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 7:42 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 7:52 pm
by zimberzimber
Oh well. Guess I'll have to stay with removing the surface component.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 9:18 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 10:31 pm
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 ¯\_(ツ)_/¯

Re: Ask a simple question, get a simple answer

Posted: Sat Nov 26, 2016 12:05 am
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.

Re: Ask a simple question, get a simple answer

Posted: Sat Nov 26, 2016 1:51 am
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

Re: Ask a simple question, get a simple answer

Posted: Sat Nov 26, 2016 2:53 am
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Nov 26, 2016 3:26 am
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Nov 26, 2016 3:57 am
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.