UESP Forums

Discuss the uesp.net site and Elder Scrolls topics.
* FAQ    * Search
* Register    * Login
It is currently Sun Jun 02, 2024 8:21 pm

Loading

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Complications with GetSecondsPassed
PostPosted: Sat Jan 21, 2017 1:47 am 
Offline
Layman
Layman

Joined: Sat Apr 26, 2014 10:48 pm
Posts: 5
ES Games: Arena, Daggerfall, Redguard, Battlespire, Morrowind, Oblivion, Skyrim
Platform: PC, Xbox, Xbox 360
UESPoints: 0
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. >.>


Top
 Profile  
 
 Post subject: Re: Complications with GetSecondsPassed
PostPosted: Sun Jan 22, 2017 5:18 pm 
Offline
Apprentice
Apprentice
User avatar

Joined: Sat Oct 17, 2015 5:10 pm
Posts: 154
ES Games: Morrowind, Oblivion
Platform: PC
Status: Subject to change without notice
UESPoints: 16
The problem is the "set state to 0" line at the top, right after the variable declarations. The timer code only executes when state = 1, but you're resetting state to 0 every frame, so the timer code only executes for one frame and then stops because state has been reset to 0. Take that line out and it should work.

Mind you, all this will do is take the player's ingredients, add the thread spool, and then play a sound 10 seconds later (and maybe not even that long--the way it's written the timer is incrementing while waiting for a button to be pressed). It doesn't delay the player getting the spool. Given what you've written, here's how I would do it (just off the top of my head--there might be a more elegant way to write this):

Hidden:
Code:
begin EG_SpinWheel

short button
short messageOn
short state
short ingred  ; 1=marshmerrow, 2=kresh fiber
float timer

if ( MenuMode == 1 )
   return
endif

if ( OnActivate == 1 )
        MessageBox, "Spin thread", "Marshmerrow", "Kresh", "Exit"
   set messageOn to 1
endif

if ( messageOn == 1 )
   set ingred to 0
   set button to GetButtonPressed

   if ( button >= 0 )
      set messageOn to 0
   endif   

   if ( button == 0 )
      if ( player->GetItemCount "ingred_marshmerrow_01" >= 5 )
         set ingred to 1
         player->RemoveItem "ingred_marshmerrow_01", 5
         MessageBox "You begin to spin thread from marshmerrow."
         set state to 1

      else
         MessageBox "You don't have the resources."
      endif
   
   elseif ( button == 1  )
       if ( player->GetItemCount "ingred_kresh_fiber_01" >= 5 )
         set ingred to 2
         player->RemoveItem "ingred_kresh_fiber_01", 5
         MessageBox "You begin to spin thread from kresh fiber"
         set state to 1         

      else
         MessageBox "You don't have the resources."
   endif

   else
      return

   endif
endif

if ( state == 1 )
   set timer to ( timer + GetSecondsPassed )
   if ( timer > 10 )
      if ( ingred == 1 )
         player->AddItem "EG_MarshmerrowThread", 1
      elseif ( ingred == 2 )
         player->AddItem "EG_KreshThread", 1
      endif
      PlaySound "Item Misc Up"
      set state to 0
      set timer to 0
   endif
endif

end EG_SpinWheel

I think that should work and do what you want it to do.

Edit: tightened up the timer code

_________________
CLIFF RACER BODY COUNT: 1059

And I ain't in it for the power
And I ain't in it for my health
I ain't in it for the glory of anything at all
And I sure ain't in it for the wealth


Top
 Profile  
 
 Post subject: Re: Complications with GetSecondsPassed
PostPosted: Mon Jan 23, 2017 6:01 pm 
Offline
Layman
Layman

Joined: Sat Apr 26, 2014 10:48 pm
Posts: 5
ES Games: Arena, Daggerfall, Redguard, Battlespire, Morrowind, Oblivion, Skyrim
Platform: PC, Xbox, Xbox 360
UESPoints: 0
Quote:
but you're resetting state to 0 every frame


Oh, thanks! I didn't know that it resets every frame, thought it was an initial assignment type thing!

and I know that it would only play the sound 10 seconds later, I had it the way I had wanted the first times I wrote it, but got tired of rearranging all that code just for it not to work, so I only did the sound as a test :P

EDIT:

I got too used to regular programming! Reading your above quote made everything click instantly. Here's the script now, working perfectly. Now just to come up with more things to make thread from... Thanks again :D

Code:
begin EG_SpinWheel

short button
short messageOn
short state
float timer


if ( MenuMode == 1 )
   return
endif

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
         MessageBox "You begin to spin thread from marshmerrow."
         DisablePlayerControls
         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
         MessageBox "You begin to spin thread from kresh fiber"
         DisablePlayerControls
         set state to 1         

      else
         MessageBox "You don't have the resources."
   endif

   else
      return

   endif
endif

if ( state == 1 )
   set timer to ( timer + GetSecondsPassed )
   
   if ( timer > 3 )
      if ( button == 0 )
         player->AddItem "EG_MarshmerrowThread", 1
      elseif ( button == 1 )
         player->AddItem "EG_KreshThread", 1
      endif

      PlaySound "Item Misc Up"
      EnablePlayerControls
      set state to 0
                set timer to 0
   endif
endif

end EG_SpinWheel


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Sponsored Links

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group