Home   Help Search Login Register  

Author Topic: Scope of variables in switch statement  (Read 4506 times)

0 Members and 1 Guest are viewing this topic.

Offline i0n0s

  • Former Staff
  • ****
Re: Scope of variables in switch statement
« Reply #15 on: 10 Dec 2008, 01:39:10 »


First is preprocessFile
Second preprocessFileLineNumbers

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re: Scope of variables in switch statement
« Reply #16 on: 10 Dec 2008, 04:12:15 »
.....
Note that there are two returned lines but it is correct because just one of them is executed. You can do the same for the other controls structures but remember that there must always be onnly one returned value.

The spawn command syntax is the same of the call command except that you can't access the value of the function. This is because the spawn command already returns the "script handler", that is a sort of script ID you can use to synchronize scripts with the command "scriptDone". The code is:

[arguments] spawn compile preprocessFile "myFunction.sqf"

or

_scriptHandler = [arguments] spawn compile preprocessFile "myFunction.sqf"

NOTE: If you use call or spawn for a function local to the script, i.e. defined with a code block variable, you don't to have to use "compile" and "preprocessFile" because the variable already contains a code block and not a text file which must be compiled first.

C++ OT:

Yeah, basically variables that counts outside a context (or a scope) are function returned values and object member variables. The last one are different because you normally declare them as "private" so the user can't access them but with the class public functions. But the idea is that.

Nevertheless there's a difference between memory automatic allocation and dynamic allocation. The dynamic allocated variables are declared with the "new" instance and exists until you explicitly delete them with the "delete" instance. Dynamic allocated variables are used for example to define arrays whith a custom size, that is you don't to have to use a constant value to specify their size but you can use a variable. Usually an automatic array (the one with the size specified by a constand value) are declared like this:

myArray = int[30];

if you want the size of the array to be a custom input value for example you must declare a dynamic array like this>

int size;
cin >> size;
int *myArray = new int[size];

where myArray is an integer pointer.

This is just to make you understand that for dynamic variables the scope rules do not apply. The array will exist until the program ends or you delete it with the command:

delete[] myArray;

Excellent! This will be useful for scripting. I suppose this is similar to threading in a way? You could then for instance check the status of several convoys roving the island by every time base x executing a master SQF that spawns a function for each convoy.

Good info Ext3rmin4tor!  :good:

« Last Edit: 10 Dec 2008, 04:14:10 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Ext3rmin4tor

  • Members
  • *
Re: Scope of variables in switch statement
« Reply #17 on: 10 Dec 2008, 11:25:56 »
Yeah, a script is indeed a thread so you can handle multithreading. You couldn't do that for SQS scripts becaues there were no script handlers.

@ionos
Now I get the difference between the two commands, it writes the line numbers and it doesn't just put the "#" simbol after the error. But the ArmA compiler is very bugged anyway, it rarely shows the true error you made, I usually debug the code myself because if you put a wrong argument for a function (for instance you put a string but you forget to close it with " ) it casts a code block error (it says "code expected") if you do that inside a control structure.
« Last Edit: 10 Dec 2008, 11:30:31 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!