0 Favourites

Else statement Construct 2

  • Hello everyone,

    Okay I wasn't sure really where to post this, I feel like its something buggy is happening but I'm not sure.

    In the attachement i have a picture of a function that toggles a local variable. A strange thing happens when I execute the function with the else statement and no extra check, the else statement seems to run even though the previous statement runs.

    It seems like the else statement runs because the variable I checked is changed in the condition prior to the else statement.

    Does the else statement in construct work like a typical programming language else, or does it actually behind the scenes check if the variable is different then what is stated in the condition?

  • I don´t have an answer for your question about Else with a condition. Mostly because there is no need for an Else when you have a condition like yours.

    In your case you would either check if bConversationLocked = 0 or = 1, then use Else or Not equal to.

    Construct2 programming is a bit different to normal programming as it is Events and Actions that runs first to bottom.

  • Couple of things. You have a local variable which will be reset immediately (i.e. next tick). Also your log messages in both functions are identical which might cause confusion when reading logs. Plus we can't see other things, like how you are calling the functions, the log messages themselves, etc.

    edit: not to mention you don't need 2 functions to do this, unless this is just experimenting

  • In the absolute, Else is supposed to indeed be executed if and only if the previous event hasn't been executed, like in a regular if/else statement in any other coding language.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • ... Mostly because there is no need for an Else when you have a condition like yours...

    I actually put that extra condition because i had some strange behavior. With the extra condition, I wasn't getting any issues.

    Couple of things. You have a local variable which will be reset immediately (i.e. next tick).....

    Ah yes, thanks, was a bit tired when I made this post, it was supposed to be static variable, I don't think it should have effected this though. Just to be clear, when running the "Toggle.." function, the "WriteToLog" function seemed to have been called twice, which made me wonder if there could be a reason for this.

    ... Plus we can't see other things, like how you are calling the functions, the log messages themselves, etc.

    edit: not to mention you don't need 2 functions to do this, unless this is just experimenting

    Yea, I think i was not clear enough in explaining the problem, the issue seemed very much to happen in the same function call. I was asking here about the else statement to be sure the else in construct functions the way I expect it too. My codebase has become quite large and I'm trying to be sure about how things work, before digging through it.

    Sometimes having 2 functions makes code clearer to read and easier to return to I should probably not call it toggle though if it has 2 functions...

    In the absolute, Else is supposed to indeed be executed if and only if the previous event hasn't been executed, like in a regular if/else statement in any other coding language.

    Thanks.

  • I will look into it again with a fresh mind.

  • Report this as a bug.

    The Else should not execute just because the value updates to pass. That's a logic bug and should never happen.

    if( foo == 0 )

    foo = 1;

    else

    // should not run. Ever.

    foo has to be anything but 0 at the if statement for else to run. Changing within the if statement should not run the else too.

  • I'm on a deadline so, I can't really look into this just yet, i have this code checked in a repo with a tag, so I should be able to find it again.

    Once my deadline is over I will make sure but I was very tired when I posted this so, its more likely i just didn't realize i was calling ToggleConversationLockOff() somewhere after the call to ToggleConversationLockOn(). Still to be safe I will check.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
0 Favourites
Construct 3 any news?
889 125,625
uzumiapps's avatar
uzumiapps
Unread hot topic
353 32,099
yojona's avatar
yojona
Unread hot topic
313 26,498
Juryiel's avatar
Juryiel