How to define scope?

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Hi dear cerberus-x fans,

I am wondering if it is possible to define scope in CX:

Say I want to re-use the same variable name in the same method:

Code:
Local y:Float = 0

Local y:Float = 0

Local y:Float = 0

however I can't, so I am using different names or:

Code:
Local y:Float = 0

y = 0

y = 0

However I find this approach a bit error-prone, I am wondering if there is a way to do it, some kind of {} pair in c/c++/java:

Code:
    {
        float y = 0;
    }
    {
        float y = 0;
    }
    {
        float y = 0;
    }


Thank you

Cheers
 

Gerry Quinn

Active member
Tutorial Author
Joined
Jun 24, 2017
Messages
153
I used to like doing that in C++, but it wasn't really to prevent errors, just to separate sequential parts of a long method into pseudo-methods. (I was never one for making many small methods unnecessarily - if 1000 lines are getting called in sequence at initialisation, a 1000 line method is what I write!)

For that situation, it's nice to be able to re-use common identifiers like i, x, y etc. If you want to re-use them but they have method scope, then the first time you write "Local x:Int", but the next time you have to write "x = 0". But it's not a major issue.
 
Top Bottom