0 Favourites

Text and local variable.

  • Hello, please can anyone tell me why "hola" is not printed when I press the cursor down ?.

    The variable "var" is local and only retains its value in the same tick if there is no "wait" action, I do not know why the text is not printed when I press the cursor down.

  • Hi, any ideas on this?

  • Hi there. Double-click on the local variable to edit and make sure Static is checkmarked. It will then work.

    This will force the variable to stay at the value it was changed to, otherwise it resets back to the initial value.

  • Hi there. Double-click on the local variable to edit and make sure Static is checkmarked. It will then work.

    This will force the variable to stay at the value it was changed to, otherwise it resets back to the initial value.

    Thanks I know that solution, but when I hit the cursor down the variable "var" takes the value 1, then the text should be written, the question is why is not the text written ?.

  • I don't understand.

    Your screenshot shows that you don't have Static checkmarked. Otherwise, it would say "Local static number var = 0".

    That is why it's not working.

  • Change on key pressed' to 'key is down' ... add 'once while true' to the same event.

    Why ?

    'on key down' is a trigger. It fires, and then the rest of the events is executed.

    So, after firing that trigger, 'it' looks up if it can execute its actions. So, it goes up, meets the Group, is the group active, then the trigger is allowed to run its actions.

    After that, 'it' starts with executing top-down. First the group (is it active or not), then resets the local var to zero, then checks if the local is 1.

    'key is down' is not a trigger, it stays at its place in the top-down run list.

    (making the var static is not a solution if you want to var to reset)

  • I don't understand.

    Your screenshot shows that you don't have Static checkmarked. Otherwise, it would say "Local static number var = 0".

    That is why it's not working.

    But when I hit the cursor down, "var" takes the value 1.

    Therefore in the following condition:

    System var = 1 Set text "hello"

    That condition should be true, after that, the tick ends and "var" is reset to 0.

    I know that if the variable is static it is solved, but I want to understand why the text is not written when press down cursor.

  • Ahh, thanks 99Instances2Go. I'll definitely remember that.

    Unfortunately, it doesn't show that in the debugger if it's not static.

  • Change on key pressed' to 'key is down' ... add 'once while true' to the same event.

    Why ?

    'on key down' is a trigger. It fires, and then the rest of the events is executed.

    So, after firing that trigger, 'it' looks up if it can execute its actions. So, it goes up, meets the Group, is the group active, then the trigger is allowed to run its actions.

    After that, 'it' starts with executing top-down. First the group (is it active or not), then resets the local var to zero, then checks if the local is 1.

    'key is down' is not a trigger, it stays at its place in the top-down run list.

    (making the var static is not a solution if you want to var to reset)

    A bit complicated for me the trigger operation, in addition I translate your message to my language.

    Thank you, I think something I understood.

  • the Mnk

    You have been wrestling with those triggers quite some times.

    Can i explain it better ? Tell me what you find complicated ? Or is it my sucky english ?

  • post deleted

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • the code is always run downwards it would not go up to check if the group is active. if the group was not active the key press trigger will not even run.

    As you wish & whatever dude.

    Allow me to quote some one smarter

    --- left out a few lines here--

    Triggers in subevents check all their parent events are true, but the "else" is checked on its own without referring to previous events in that case, so it probably doesn't do what you want.

  • the code is always run downwards it would not go up to check if the group is active. if the group was not active the key press trigger will not even run.

    As you wish & whatever dude.

    Allow me to quote some one smarter

    > --- left out a few lines here--

    > Triggers in subevents check all their parent Events are true, but the "else" is checked on its own without referring to previous events in that case, so it probably doesn't do what you want.

    >

    I wasn't trying to be smart / rude. Sorry if it came over like that. I was just trying to be helpfull with what can be quite a confusing subject.

    I am still pretty much a noob here and very happy to be corrected for the benefit of myself and others reading.

    Ashley is talking about Triggers in sub events but you are talking about Trigger events inside Groups.

    My thinking was that, as the code runs down, if it finds a deactivated group then it just bypasses all the Events within. So its like that Trigger Event doesn't even exist for that cycle.

    But you are saying that Groups are actually just Events with a "Is group active" flag? And that if a Group is deactivated the Trigger Events inside still fire but they also go up to check if the parent Group Event is active before running any of their Actions???

    I am happy to entertain that, it makes sense, and the outcome should be the same.

    If this is correct I am happy to delete my post above to avoid confusion.

    Are we 100% that those triggers are still checked? It would be good to know as I read a lot of people on here spending a lot of time using groups to "Optimize their code" rather than just for turning bits on and off here and there. It would make that sort of optimization pointless if all those triggers are still being checked.

  • That is actual very easy to show, so you dont have to take me on my word.

    https://www.dropbox.com/s/ezceqtejd2u3x ... .capx?dl=0

    In fact, it is not exactly known when a trigger fires insight the tick. For the 'hardware readers' (mouse, keyboard, Ajax) there is no rule. It depends on the device and on the browser. Some triggers just have to run at the start of a tick, else they dont make sense. The 'On landed' by instance. Platform has a 'push out of solid' routine. Evaluating a position under 'On landed' should give the position after the 'push out of solid', even if you set the position to something else later in the events.

    The only thing that is for sure, is that a trigger fires only once in the same tick.

    A Group is just a condition as all other conditions. It has a system Boolean 'activated', false or true. And it will evaluate that Boolean every tick. Every condition under a condition is a sub condition.

    So, again. What happens of you bury a trigger (there are false triggers too) deep (or not that deep) down in sub events ? It triggers and looks up to find out if it can run its actions/subs.

    Do not quote me (stealing the possibility for me to erase my dumb comments, and dude, this whole forum has dumb post from me, till i learned something about the subject) and then offer to erase your own posts. Tyvm.

  • 99Instances2Go

    Holy cow......OK..i see.....well, that changes a lot of things.......

    thanks for taking the time......I am enlightened...

    will delete my post above......(and try to stop being a noob)....

    cheers....

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)