[How do I] Local variables and scope problem

Get help using Construct 2

Post » Fri Sep 18, 2015 12:36 pm

Image

What am I doing wrong here? Text object allways returns 111, even thou it should be touch.x.

If I put the "Set text to Variable1" right after I change the variable. Text object displays the touch.x
B
67
S
23
G
9
Posts: 172
Reputation: 7,351

Post » Fri Sep 18, 2015 1:56 pm

You can not use a Local here. It needs to be Global. "On touch" is a trigger, which happens outside of the event loop, so the scope only lasts for event 2. Events 3+ run on the next tick, which will reset the Local back to it's default of 111.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Fri Sep 18, 2015 2:50 pm

@blackhornet
Thank you very much for clarifying this out. So does this mean that we can't change local variables with triggers?
B
67
S
23
G
9
Posts: 172
Reputation: 7,351

Post » Fri Sep 18, 2015 2:57 pm

You can change local variable, but they work in specific scope of events and when that scope ends local variable is automatically reset.

Read here to get more info about local variables https://www.scirra.com/manual/83/variables
ImageImageImageImage
B
157
S
66
G
42
Posts: 2,603
Reputation: 35,343

Post » Fri Sep 18, 2015 3:46 pm

You can set local variables to "static" so their value persist.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Sep 18, 2015 6:11 pm

@shinkan @Magistross

Thank you very much. This was a great help!
B
67
S
23
G
9
Posts: 172
Reputation: 7,351


Return to How do I....?

Who is online

Users browsing this forum: Armench, FabianB, farsen and 10 guests