variables and scopes - combo/function
3 posts
• Page 1 of 1
variables and scopes - combo/function
Within functions I can use identical named local variables without errors like this:
But within different combos trying to create a local variable with same name I get the error " GPC error: <scriptname>: Invalid symbol redefinition 't8' "
or without redefintion of t8 I get: " GPC error: <scriptname>: Variable not accessible at current scope 't8'. "
So a local combo variable isn't really local ? Or shouldn't I use local variables in combos at all ?
- Code: Select all
void Test() {
int8 t8;
}
void Test2() {
int8 t8;
}
But within different combos trying to create a local variable with same name I get the error " GPC error: <scriptname>: Invalid symbol redefinition 't8' "
or without redefintion of t8 I get: " GPC error: <scriptname>: Variable not accessible at current scope 't8'. "
So a local combo variable isn't really local ? Or shouldn't I use local variables in combos at all ?
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: variables and scopes - combo/function
Combos are an extension (or continuation) of the "main" procedure. The variables declared within combos are static allocated (when the script is loaded), but only available within the combo scope.
if you want use dynamic allocated variables on combos, you can do by calling a function;
or, to have t8 accessible in all combos, declare it globally (outside main, init or combos)
if you want use dynamic allocated variables on combos, you can do by calling a function;
or, to have t8 accessible in all combos, declare it globally (outside main, init or combos)
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: variables and scopes - combo/function
J2Kbr wrote:Combos are an extension (or continuation) of the "main" procedure. The variables declared within combos are static allocated (when the script is loaded), but only available within the combo scope.
if you want use dynamic allocated variables on combos, you can do by calling a function;
or, to have t8 accessible in all combos, declare it globally (outside main, init or combos)
Thanks for the explanation.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
3 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 198 guests