OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: LCD on 05 Sep 2007, 18:01:32
-
im tryin to add couple of values to an array thro a function
da function is like dat
_arr = _this select 0;
_val = _this select 1;
_arr = _arr + [_val];
but it doesnt realy add em....
i exec da script like dat
bla = [localalarm,group this] execVM "general\add2arrray.sqf"
wat i intend doin w/ dis is bypass da way ArmA does inits @ da order ArmA likes... so i just create da array in da init.sqs nd den have all da groups add demself 2 it
LCD OUT
[edit] i actualy just seen a small eror in what i wrote... it seems ill still have 2 init da array b4 runnin da script... but i know how not 2 make ArmA interfare w/ dat... still need fixin da script tho :D
-
Should be easy enough: the only problem is I don't actually know if there're any changes to how this works in .sqf. I suck at .sqf :D
I -think- the problem is you can't really do the global-local variable thing very easily, i.e. that you can go
_localVariable = GlobalVariable
That -does- make the _localvariable carry the same weight as the globalvariable (I think), but changing the localvariable will not change the global one. So, basically...hum. How is it all called and what's the point of the whole thing?
Wolfrug out.
-
_value1 = 1
_value2 = player
_array = [_value1] + [_value2]
is that what you try to solve using a function? :blink:
-
i wanna put some groups in an array... but i dont wanna waste time finding out each time wich of da groups is initialized 1st... (cuz dere is were i need 2 put da arrayname = [] thing) so what i wanna do is just run da function 2 add da groups 2 da array... so what i do is send da arrayname (localAlarm) nd da groupname (group this) nd have da script add da group 2 da array...
so i call it like dat
bla = [arrayname,group this] execVM "general\add2arrray.sqf"
_arr = _this select 0;
_val = _this select 1;
_arr = _arr + [_val]
hoping 2 fill da original array...
hope dis time its clear enough :D
LCD OUT
-
then it was clear since first time, but where is the problem? and why do you need a function?
localalarm = []
localalarm = localalarm + [group]
just make sure localalarm is set to [] before anything else.
-
i wanna do difrent arrayz 4 difrent bases... nd i dont wanna name da groups (saving on variables 2 prevent savegame bugs...)
now prob is dat units init is exacuted b4 init.sqs/init.sqf... nd i dont wanna spend time figuring wich init comes 1st 4 each base....
LCD OUT
-
Problem in your first post is that you forgot to initialise the array (_array = []) as mandoble wrote. Does that solve your problem?
-
may be your function should look like:
_arr = _this select 0;
_val = _this select 1;
if (!isNull _arr) then
{
_arr = _arr + [_val];
}
else
{
_arr = [_val];
}:
_arr
-
I remember reading somewhere that arrays and function do not mix, at least in OFP. Maybe you should strip this back to basics.
Create a function that readin in an array of numbers then echos them in a hint.
Then try and change an array with another function and hint it out. This should tell you whether arrays can be altered by a function and or whether sqf files can deal properly with functions.
On a side note does anyone know if sqf files can RETURN functions??
-
arrays and functions work nicely in ArmA. sqf files executed using execVM cannot return any result, the returned value is always the handler of the sqf script being executed.
-
_arr = _this select 0;
_val = _this select 1;
_arr + [_val]
should do the trick
-
Thanks Mandoble
Always good to be kept on the ball (if you know that expression)
Pad