Download

Variables reset when moving items.

So I have some custom items (Saddles) I have created unique variables on them. I can set these during runtime successfully, but when I move the item from one inventory to another the variables completely reset.

Why does this happen?

Maybe you are creating new items instead of “moving them”?

well, I’m just dragging in from one inventory to another, just like normal in game. Does this process destroy from an inventory and then recreate in the new inventory?

If so how would I prevent the loss of those values?

It has do be possible or else stats like durability would constantly reset right?

As far as I’m aware, there is no “moving” of things between things. It’s all akin to dropping and picking things up. The actor/item is destroyed and a new one is given.

In saying that, I don’t know for sure how stats are transferred between the objects, but I would suspect that there is hidden functions/logic that they use for handling such things, and they most likely grab the stats they need from the object before destroying it, create the new object with the stats taken from the old and then delete the old one.

That’s how I see it working anyway.

How to make this work with custom variables, I wouldn’t have the slightest idea. My ACM mod uses an inventory item to store some data for my mod for each player that uses it in itself, but I too discovered the variables being deleted upon dropping/transferring, never really bothered looking into it though.

-WM

I got some advice on the IRC (Thanks Mezzo)

So the plan is that, since the item is destroyed on every transfer like that, I’m going to leverage an already existing variable that the game already persists through those changes. The variable is a float, and I just happen to have 2 variables that need to be stored.

So what I am going to do is set up a switch system for each variable that will “encode” it into a number (as string) and then append the two number together with a decimal in between, then convert it to a float. Then when the script is called that needs to know those values I do the reverse and effectively “decode” the value using switches to get the information I need.