luado-whiledefold

Defold on_input while loop crashing


I am trying to have a while loop in my on_input that will continuually execute piece of code every few seconds

    while(action_id == hash("click"))
    do
        print("Going")
    end

I have tried moving it into other functions that are called by on_input, but every time a run this piece of code it crashes the program.

EDIT: I found that I was supposed to make sure the condition becomes false, stupid mistake.


Solution

  • The on_input() function is called by the engine every frame that some kind of input is received. What you are doing is entering an infinite loop during the frame when you receive an action_id that is "click". The loop will never complete since action_id will not change and the engine will lock up.