Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Every Frame While Loop Crashes Game? — Gideros Forum

Every Frame While Loop Crashes Game?

edited December 2017 in General questions
So, I wanted my game to call a function every 1.5 seconds, so I added the below code to my On Frame Event function and, the game doesn't load. It says it uploaded in the console, but I either get a pinwheel cursor on my computer, or nothing starts up if I'm testing on my phone. It runs fine without this bit:
while isMoving == true do
	timer = Timer.delayedCall(1500, spikeFall)
  end
Any ideas? Am I doing something wrong?

Thanks!

Comments

  • The problem is most likely that the variable isMoving remains true, causing an infinite amount of timers being created each frame.

    You probably want to replace the while statement with if, and make sure it's only run once by setting a Boolean variable;
    if isMoving == true then
       if spike_is_about_to_fall ~= true then
          timer = Timer.delayedCall(1500, spikeFall)
          spike_is_about_to_fall = true
       end
    end
    And then set spike_is_about_to_fall to false once the spike has fallen. :)

    Niclas

    Likes: antix

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • timer = Timer.new(1500)  
     
    function onTimer(e)
     
    	if  isMoving == true then
    		print(os.timer())
    		--spikeFall()
    	else
    		Timer:stop()
    	end
     
     
     
    end
     
    timer:addEventListener(Event.TIMER, onTimer)
    timer:start()
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
Sign In or Register to comment.