Home   Help Search Login Register  

Author Topic: adding 2 array thro function  (Read 1675 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
adding 2 array thro function
« 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

Code: [Select]
_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
« Last Edit: 05 Sep 2007, 18:03:05 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: adding 2 array thro function
« Reply #1 on: 05 Sep 2007, 20:25:06 »
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.
"When 900 years YOU reach, look as good you will not!"

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: adding 2 array thro function
« Reply #2 on: 05 Sep 2007, 20:26:15 »
Code: [Select]
_value1 = 1
_value2 = player
_array = [_value1] + [_value2]

is that what you try to solve using a function?  :blink:

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: adding 2 array thro function
« Reply #3 on: 05 Sep 2007, 21:45:14 »
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"

Code: [Select]
_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
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: adding 2 array thro function
« Reply #4 on: 05 Sep 2007, 22:05:46 »
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.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: adding 2 array thro function
« Reply #5 on: 05 Sep 2007, 22:08:52 »
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
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Cheetah

  • Former Staff
  • ****
Re: adding 2 array thro function
« Reply #6 on: 05 Sep 2007, 22:36:25 »
Problem in your first post is that you forgot to initialise the array (_array = []) as mandoble wrote. Does that solve your problem?
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: adding 2 array thro function
« Reply #7 on: 05 Sep 2007, 23:19:58 »
may be your function should look like:
Code: [Select]
_arr = _this select 0;
_val = _this select 1;
if (!isNull _arr) then
{
   _arr = _arr  + [_val];
}
else
{
   _arr = [_val];
}:
_arr

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re: adding 2 array thro function
« Reply #8 on: 07 Sep 2007, 13:18:10 »
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??

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: adding 2 array thro function
« Reply #9 on: 07 Sep 2007, 13:40:01 »
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.

Offline Wiper

  • Members
  • *
Re: adding 2 array thro function
« Reply #10 on: 08 Sep 2007, 02:03:37 »
Code: [Select]
_arr  = _this select 0;
_val  = _this select 1;

_arr + [_val]

should do the trick

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re: adding 2 array thro function
« Reply #11 on: 08 Sep 2007, 10:37:23 »
Thanks Mandoble

Always good to be kept on the ball (if you know that expression)

Pad