You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please introduce scope block concept for named local variables.
Idea is to add new keyword scope which would be used in pair with end to create blocks (same as for example const).
Block like that would result in reset of used local variable counter value used to allocating named local variable indexes.
Scope should also make previously allocated local variable names not accessible.
It should not be possible to nest scope blocks. This will create two possible states: script global scope, or local scope.
int a // 0@
int b = 4 // 1@
int c = // 2@
scope
int d // now 0@ instead of 3@
int e = b // error, b is unknown identifier
int a = 1 // 1@ - allowed 'a' is new identifier
end
Scope block should not affect global $ variables.
Scope block should not affect local @ variables with indexes <0 and >31 (future virtual variables: #270)
This feature would enable us to use named local variables within cleo_call [0AB1] functions, which actually implements concept of current scope in term of storing-restoring all local variables along with scope traversing via call-return opcodes.
scope
float a, b, c // input arguments
:FUNC
float d
d = a
d += b
cleo_return 1 d
end
If implemented this way it wil even work correctly with nested cleo calls.
This feature will be also reused in future functions feature #263, as function keyword will inherit (and extend?) behaviour of scope.
Scope block will be also useful for enclosing code of missions and script sub-threads (create script from label), as these two spawn their own set of local variables.
Activity
[-]Scoped local variables[/-][+]Scoped local variables RFC[/+]x87 commentedon Nov 2, 2023
#145
MiranDMC commentedon Nov 16, 2023
Scope block will be also useful for enclosing code of missions and script sub-threads (create script from label), as these two spawn their own set of local variables.
[-]Scoped local variables RFC[/-][+]Scoped local variables in SCM scripts RFC[/+]x87 commentedon Feb 7, 2024
4.0.0-beta.5 allows declaration of custom variables in functions in main.scm
x87 commentedon Apr 21, 2024
4.0.0-beta.8 allows declaration of custom variables in missions and external scripts.
the only remaining place where custom variables are not available now is a non-function code in MAIN section of main.scm
x87 commentedon Dec 8, 2024
Custom variables in SCM missions should be allocated starting from 34@. This is how it's done for .CM (CLEO Missions)
x87 commentedon Mar 16, 2025
Implemented in 4.1