variables and scopes - combo/function

GPC2 script programming for Titan Two. Code examples, questions, requests.

variables and scopes - combo/function

Postby Scachi » Sat Sep 24, 2016 7:45 pm

Within functions I can use identical named local variables without errors like this:

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 ?
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: variables and scopes - combo/function

Postby J2Kbr » Sun Sep 25, 2016 6:32 am

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)
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: variables and scopes - combo/function

Postby Scachi » Sun Sep 25, 2016 7:06 am

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.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 219 guests