Post new topic    
Liquid Metal Slime
Send private message
Help: "Stop Timer" not working as expected... 
 PostSun Sep 28, 2014 7:57 pm
Send private message Reply with quote
Now that I have got the timer working as intended for my game, I was wanting to put in a debugging key-press which allows me to turn timer #1 on/off. So I made the following code in my On-Keypress Handler:

Code:

...
if(key is pressed(key:0)) then(
      ### Turns hallucinate0 on/off
      if (check tag (17) == off) then(
        set tag (17, on)
        RGBConstraint := 100
        Red0 := 0
        Blue0 := 0
        Green0 := 0   
        hallucinate0
      ) else (
        set tag (17, off)
        hallucinate0Reset
      ) 
    )
...


The hallucinate0 code is:
Code:

script, hallucinate0, begin
   If (RGBConstraint <95> 105) then(
     set tag (16, off)
   )
   
  If (check tag (16) == true) then( 
    increment (Red0, 0)
    increment (Green0, 0)
    increment (Blue0, 1)
    increment (RGBConstraint, 1)
  ) else ( 
    decrement (Red0, 0)
    decrement (Green0, 0)
    decrement (Blue0, 1)
    decrement (RGBConstraint, 1)
  ) 
 
  reset palette
  tweak palette (Red0, Green0, Blue0)
  update palette
 
  # Repeat this script again in 1 tick without blocking other scripts
  set timer(1, 0, 1, @hallucinate0, 0, (timerflag: menu))
end


And the hallucinate0Reset code is:
Code:

script, hallucinate0Reset, begin
  stop timer (1)
  reset palette
  #suspend timers
end


I don't think there is a problem with my on/off button since it seemed to work when I used "suspend timers" in place of "stop timer(1)," but I can't use that feature since it suspends all timers.

Is there something I'm not understanding about "stop timer," or is there some other reason that it may not be working?

Thanks, I'm sorry for the sudden swell of questions I've been asking in the past few day... guess it means I'm active on my game though.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal King Slime
Send private message
 
 PostMon Sep 29, 2014 5:35 am
Send private message Reply with quote
As I said in the other thread, on-keypress triggers have precedence over timer triggers. so what happens is this:

-hallucinate0 triggered by timer
-on keypress script triggered
-on keypress script runs
-stoptimer(1) is called
-on keypress script finishes
-hallucinate0 runs
-hallucinate0 sets timer to retrigger itself

Use a tag to stop hallucinate0. Byt the way, your script was mangled. Tick "Disable HTML in this post" when posting scripts.
Liquid Metal Slime
Send private message
 
 PostMon Sep 29, 2014 5:52 am
Send private message Reply with quote
Alright works good now, I wasn't thinking it through properly. Put the check tag in the wrong spot.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Display posts from previous: