How do I do this Or Sentence ?

Get help using Construct 2

Post » Tue Jan 13, 2015 6:42 pm

Local scope vs. global scope ;)
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Tue Jan 13, 2015 8:29 pm

Magistross, you are awesome.
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Tue Jan 13, 2015 11:30 pm

Magistross wrote:Well then, if it must run once between 0 <-> 6 value permutations too, I guess you could use sub-events and a local flag variable. Like this :
triggerOnceCombo.PNG


On a second look:

flagExecute is set to 1 once if Whatever is changed to 0 or 6, also when changing from those numbers. However, flagExecute stays the same value (1) when Whatever changes drom 0 to 6 not solving the issue completely. Also while "flagExecute = 1" is true It is triggering all events included in "flagExecute = 1" every tick.

Simply adding a "Set flagExecute to 0" at the end of the "flagExecute" event list should round it up ;)
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Wed Jan 14, 2015 3:03 pm

@MultipleChoice flagExecute is a local variable. It get initialized to 0 implicitely every tick, no need to do anything ! ;)
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Wed Jan 14, 2015 3:15 pm

Okay, there I learned something. I did not get, what local numbers are exactly used for.

Can you also please explain then, if and why a function is a disadvantage in this case?
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Wed Jan 14, 2015 3:15 pm

Okay, there I learned something. I did not get, what local numbers are exactly used for.

Can you also please explain then, if and why a function is a disadvantage in this case?
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Wed Jan 14, 2015 3:42 pm

Local variables are just that, their scope is limited to where they were declared. The main reason to use them is to not clutter the global namespace. There also exists static local variables, their scope are also limited to their declaration block but they don't get reinitialised to their default value.

As for using a function instead, I would probably have gone that way too. But Toddler did not want to clutter his function namespace with a function that he probably only use for one particular context. So I provided an alternative ! ;)
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Wed Jan 14, 2015 4:51 pm

Magistross wrote:But Toddler did not want to clutter his function namespace


I understand, but why is that bad in any case? Does it cause performance issues?
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Wed Jan 14, 2015 5:18 pm

It's mostly a personnal preference, it's not more nor less performant either way. But on larger projects, a clean global namespace is a blessing, for obvious reasons.
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Wed Jan 14, 2015 5:46 pm

Got it, thanks.
B
8
S
3
Posts: 197
Reputation: 1,207

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests