Перейти к содержимому

Фотография

Stack Quantities


  • Пожалуйста, авторизуйтесь, чтобы ответить
1 ответов в этой теме

#1
Jereniva

Jereniva
  • Members
  • 114 сообщений

I've already found a work around for dealing with removing some of a stack (thanks long time ago to KevL!)

 

But, I was messing around with something and through use of debug messages, I can't figure out how the game engine is executing.

 

Here's the code snippet...

    SendMessageToPC(oPC, "You have " + IntToString(nTotalItem));
    SendMessageToPC(oPC, "Your balance after should be " + IntToString(nBalance));
    TakeNumItems( oPC, sItemTag, nQuantity );
    SendMessageToPC(oPC, "NPC took " + IntToString(nQuantity));
    GiveNumItems(oPC, sItemTag, nBalance);
    SendMessageToPC(oPC, "Gave back " + IntToString(nBalance));

If running this in a Actions event of the conversation, you see all these messages fine, EXCEPT that AFTER the "Gave back..." message you then see the message that system generates when it takes an item from you "Lost (the item)"

 

I have a fix for this, I am just trying to understand why the above does not behave as expected, and why the system's "Lost item" message comes after all of my SendMessages, and does the take item at that point.

 

I assume that clicking the PC response line is what triggers an Action sequence, but am I wrong? Is it queued somehow?

Just curious, knowing this may help me with something later... 

 

Added, I only see this problem in the Action of a conversation, that script above fires as expected in the On Used or elsewhere.



#2
kevL

kevL
  • Members
  • 4 052 сообщений
The engine has some mysterious ways of deciding the order of executions. I can't speak to this particular case, but think of DestroyObject() -- the object won't be destroyed until after the script finishes. Eg, this will [should] work:

object oItem = GetObjectByTag("rattail");
DestroyObject(oItem);
if (GetIsObjectValid(oItem)) SendMessageToPC(oPC, "The item still exists.");
But (very) soon after the script finishes the item will no longer be valid.

Several other functions have similar behavior. Beware of using things like AssignCommand, ActionDoCommand, DelayCommand, etc. They *might* not happen within the context of the script itself. on the other hand such behavior can be useful.

Regarding the discrepancy between a conversation and an OnUsed event ... there's likely a "state machine" that decides if/when and in what order conversation-clicks and event-hooks and anything else is allowed to execute code, or register hardware interrupts, etc etc etc. So in this case (the conversation) I'd guess that all the actions/print from your scripted code is handled before the actions/print from the conversation-action-result.

The OnUsed event, then, wouldn't have that discrepancy and instead allows the actions/print to happen in the sequence we'd expect. (Note, we really don't know the order of the actions, all we see here is the print.)