Else statement Construct 2

Discussion and feedback on Construct 2

Post » Tue Mar 10, 2015 2:40 am

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?
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 4
Reputation: 283

Post » Tue Mar 10, 2015 7:40 am

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.
Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

Post » Tue Mar 10, 2015 8:28 am

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
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Mar 10, 2015 10:58 am

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,329
Reputation: 71,300

Post » Tue Mar 10, 2015 12:21 pm

frostyelk wrote:... 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.

codah wrote: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.

codah wrote:... 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...

Kyatric wrote: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.
B
5
S
1
Posts: 4
Reputation: 283

Post » Tue Mar 10, 2015 12:26 pm

I will look into it again with a fresh mind.
B
5
S
1
Posts: 4
Reputation: 283

Post » Tue Mar 10, 2015 2:24 pm

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.
B
92
S
18
G
9
Posts: 2,455
Reputation: 15,113

Post » Tue Mar 10, 2015 3:34 pm

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.
B
5
S
1
Posts: 4
Reputation: 283


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests