Local?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1891
Joined: Sat Feb 23, 2008 11:15 pm

Local?

Post by Kjell »

:!:

Came across some strange behavior .. and realized / found out that locally defined variable are currently actually global / static ( unlike what I thought before ). While the script editor does prevent you from accessing variables that are defined in another scope, you can access the variable from another script ( so it hasn't been freed + re-initialized ).

For example in the first ZExpression ..

Code: Select all

for(int A=0; A<64; ++A){}
.. and in the second ..

Code: Select all

int A;
Variable = A;
.. results in the Variable being assigned 64.

Feature or bug? :wink:

K
User avatar
VilleK
Site Admin
Posts: 2280
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Variables are not initialized by ZGE before they are used so their initial value is undefined.

In your example it is not that both variables are named "A" that gives this behavior, instead it is that it is the first local variable in each expression. Local variables are defined on the ZGE expression evaluation stack which is not cleared between expressions. If the first expression has "int a,b" and the second "int b,a" then the variables may keep their value between expressions (swapped so a=b, b=a), but lets just say it is not something to rely on :).
User avatar
Kjell
Posts: 1891
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

Ah I see, that's good to know ( shouldn't use this "feature" then ) ~ Thanks for clearing that up!

K
Post Reply