Local Var

Get help using Construct 2

Post » Sat Nov 12, 2011 2:27 am

If i have a few Local vars as the first events in a group then i have 4 sub groups, the local vars should be accessible in the sub groups because the local var has been defined? or am i mistaken? i had a bunch of global vars that i decided to change to local so i could re use the code for multiple levels and no matter where i put the local vars i cant get the event that read the global earlier to read the local now.
B
15
S
1
G
2
Posts: 62
Reputation: 1,696

Post » Sat Nov 12, 2011 2:42 am

Never mind i found my answer, i did not realize that local variables will reset every tick.
B
15
S
1
G
2
Posts: 62
Reputation: 1,696

Post » Sat Nov 12, 2011 2:50 pm

Yes, just to clarify:
- global variables persist their values, and local variables reset every tick
- both global and local variables can be accessed by sub-events and sub-groups, but local variables cannot be accessed by parent events or groups.
This is how variables work in programming languages, and C2 is designed to match that.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Sat Nov 12, 2011 3:17 pm

I understand, thank you for your explanation
B
15
S
1
G
2
Posts: 62
Reputation: 1,696


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, LeFuji, RookieDev, TRMG, Yahoo [Bot] and 19 guests