Aller au contenu

Photo

Stores item stacks and local variables


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
Phaenan

Phaenan
  • Members
  • 315 messages
Oo~okay.

I just spent half an hour hunting a bug crippling my addon, and finally got my hands on it. When SetItemStackSize (or CreateItemOnObject with a nStackSize greater than 1) is used on an item with a variable inherited from the resource (and a custom var_items_blabla table) the items "created" to fill the stack with size-1 items will not get the local variable from the resource if the stack is owned by a store inventory. Not until they are separated from the stack and the game is saved/reloaded.

For instance when I create my ingots in the stores inventories, here what I do :
- http://pastie.org/756418 (excerpt from a script fired by prcscr upon area load, if that detail is important)
As in : if a stack of the relevant resource already exist, I change the stack size, and if no stack is found, I create the stack directly. Either way, the items taken from the stack won't have the custom local variable : it's automatically resetted to the var_items_blabla table default value. Only the item at the bottom of the stack (if you buy items one by one, that the last one remaining in the stack) gets the proper variable value. :mellow:
Funny thing  is none of this happens when the stack is created / modified elsewhere, like inside the party inventory.

That's the kind of sneaky bugs that can drive me crazy, and so I thought others may like to know...

As for a fix, well I'm trying to look into it without having to reduce the BITM max stack size to 1... Even manually setting the local var upon stack creation doesn't work. (the value is glued to the default)

Modifié par Phaenan, 25 décembre 2009 - 04:43 .


#2
Craig Graff

Craig Graff
  • Members
  • 608 messages
Using CreateItemOnObject with a stack size of 1 in a loop works, last I checked. But that was with a base stack size of one as well - so I'm not sure if that will work with items that are meant to be stackable. I believe the bug exists because of setting the stack size to greater than one for items that are only supposed to stack to one (possibly this is only in stores because they allow stacking of everything in a slightly different way than the other inventories).

My theory probably doesn't hold any water if you were already testing items that have a base stack size of greater than one, though. In general, I would suggest using local variables only on those items that have a base stack size of one, since the rules for combining stacks with different values set are likely sketchy at best.

#3
Phaenan

Phaenan
  • Members
  • 315 messages
Off the top of my head, those items were of the "other - generic stackable" base type. However I didn't do any intensive testing once I realized what the issue was, mainly because ... well, it's not that simple to test actually, since separating items from stacks and testing their var once appart can be quite burdensome. So I'm not sure of the hows. Just noted that it worked fine when the scripts created the stacks in the party inventory, but moving those items back to the store's (with MoveItem() right after CreateItemOnObject()) was enough to mess the local vars.
It's as you said, in the end : I'll prolly stay away from that in the future. I was trying to spare a table linking itemtags to some data, but it pretty much backfired on me, huh. ^_~"

Modifié par Phaenan, 25 décembre 2009 - 09:36 .