I'm not new to scripting, but I can not for the life of me get this timer to work. I have tried it about a dozen different ways. Right now here's how I have it :
Code:
begin EG_SpinWheel
short button
short messageOn
short state
float timer
set state to 0
if ( MenuMode == 1 )
return
endif
set timer to ( timer + GetSecondsPassed )
if ( OnActivate == 1 )
MessageBox, "Spin thread", "Marshmerrow", "Kresh", "Exit"
set messageOn to 1
endif
if ( messageOn == 1 )
set button to GetButtonPressed
if ( button >= 0 )
set messageOn to 0
endif
if ( button == 0 )
if ( player->GetItemCount "ingred_marshmerrow_01" >= 5 )
player->RemoveItem "ingred_marshmerrow_01", 5
player->AddItem "EG_MarshmerrowThread", 1
MessageBox "You begin to spin thread from marshmerrow."
PlaySound "Item Misc Up"
set state to 1
else
MessageBox "You don't have the resources."
endif
elseif ( button == 1 )
if ( player->GetItemCount "ingred_kresh_fiber_01" >= 5 )
player->RemoveItem "ingred_kresh_fiber_01", 5
player->AddItem "EG_KreshThread", 1
MessageBox "You begin to spin thread from kresh fiber"
PlaySound "Item Misc Up"
set state to 1
else
MessageBox "You don't have the resources."
endif
else
return
endif
endif
if ( state == 1 )
if ( timer > 10 )
PlaySound "Item Misc Up"
set state to 0
endif
endif
end EG_SpinWheel
I created the base script and it worked perfectly just as expected. Then I decided I would try adding a delay before the player receives the spool. At first I had the timer logic inside the first button with the sound and additem in the timer check. It executed all the code except what came after the timer check (so it took the marshmerrow but never played sound and added spool to inv)
Since then I've tried shifting things around adding things solving it differently. I changed it to rely on the state variable a few tries ago... I checked the the other scripts with timers in game a million times, checked wiki documentation, googled around. None of it worked!
I'm starting to wonder if maybe the MessageBox or buttons create problems with GetSecondsPassed method? Or maybe I overlooked something and can't see it because I'm too tangled up. >.>