Jump to content
Sign in to follow this  
VictorFarbau

Pointer structures available?

Recommended Posts

Hello,

I was wondering if anybody knows this. Are there any pointers available in the scripting language of ArmA?

In my current project I have a master script that spawns a couple of child processes and they all depend on one or more global variables which are supposed to control actions of the child processes. I don't want to hard code the global variable names into each single script. This would be pointless looking at future extension of this mission and the names might change anyway.

But I haven't found a way to pass on a pointer reference to scripts. All I can pass on using the [x] exec "y.sqs" syntax is absolute values or strings but no references.

Anybody ever had a genius idea how to overcome this?

Thanks,

Victor

Share this post


Link to post
Share on other sites

There are no reference variables (pointers if you will) in ArmA scripting language to my knowledge. If you don't want tons of global variables and want them to be expandable use global arrays (arrays can be of mixed type and contain other arrays as well and the arrays can be asymmetric).

If you have dynamically created processes you will need to write a control script to manage the array accordingly and pass the script the elements of the arrays that are reserved for them. I have done this in OFP already so it is certainly doable. But it's not the easiest thing to do. Maybe someone else has a better solution.

EDIT: Oh forgot this. Array indetifiers contain a reference to their array. Maybe you could exploit this for your needs. I haven't tested this yet fully but if I remember right then when you do

_a = [1,2,3];

_b = _a;

and then you edit _b the changes also affect _a and vice versa.

Share this post


Link to post
Share on other sites

Need more info for the situation. You might need to elaborate on what these global variables are: object variables, string variables or what.

Not sure if this is relevant for you, but if they're object variables, you may find the following handy:

vehicleVarName

setVehicleVarName

The string value you assign to setVehicleVarName can be modified with the Format command. Eg:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">object2 setVehicleVarName Format[ "MyGlobalVar%1", _counter ];

where _counter is a number.

- OR -

object2 setVehicleVarName Format[ "%1%2", _var1, _var2 ];

where _var1 and _var2 are strings.

Share this post


Link to post
Share on other sites

Before I answer to the good comments above let me clarify what my problem is using a simplified scenario:

I have a global variable called "sector1alert". This basically watches for intrusion of a given sector. If "sector1alert" is "1" then 10 sub-scripts will be spawned that place a mine each in that sector and wait for proximity of an enemy. Inside, each of the 10 subscripts must know whether "sector1alert" is still "1" - if it is back to "0" each script must exit. Easy to realize if I am hardcoding the "sector1alert" part into the subscripts.

Here's the catch:

What if I need to monitor a variable amount of sectors each time? How can I make sure that each spawned script looks at the right sectorXalert variable?

Ok, I'll create an array and can pass on each element to the subscripts a la:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

alerts = [sector1alert,sector2alert,sector3alert...sector99alert]

[alerts select _index] exec "placemines.sqs"

[alerts select _index+1] exec "placemines.sqs"

...

Problem will be that the subscripts will receive the actual value of the "_alerts select _index" reference (so "1" or "0") but not the variable name so they can't check the ongoing state of this variable, they have no way of referencing it.

Man, this is a lot of explaining for a real simple issue smile_o.gif Hope it is at least a bit more clear now. I need global references / pointers to global variables since passing on the variable names simply doesn't work - only the values get passed on that way.

Regards,

Victor

Share this post


Link to post
Share on other sites

@Donnervogel:

I have to say that I am always writing missions and scripts 100% Multiplayer compatible. I know a lot of problems stem from this and would never occur in SP setup in the first place.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a = [1,2,3];

_b = _a;

This is a good thought and straight to the point - but it doesn't work across scripts since the local reference is lost. And global references is what I am looking for.

Regards,

Victor

Share this post


Link to post
Share on other sites

well the method with global arrays containing the information and a control script managing the array worked flawlessly in MP with the according publicvariable stuff. Haven't tried it in Arma yet but I see no reason why it wouldn't work. It's just rather complicated to write such a system.

Share this post


Link to post
Share on other sites

I am afraid that's not the point Donnervogel. As said, I just need a way how to pass on global variable names to scripts.

All I get is their values instead when I pass them on. I guess this means no pointers no luck here.

Victor

Share this post


Link to post
Share on other sites

you can pass the name of the variable as a string to a script and then you can try something like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_varName = _this select 0;

call compile (_varName + " = 1");

Is that what you want?

Share this post


Link to post
Share on other sites

There are a couple of solutions to what you want to do (ie "passing by reference").

First, you could create a single-element array containing the global value. As has already been stated, array names are effectively pointers so you could do this:-

myVar = [1] ;

[myvar,5,6] call func

func = {

_mv = (_this select 0) select 0 ;

} ;

_mv will be set to whatever value myVar holds when func is called.

Alternatively you could pass in the name of the variable as a string then compile and run code to get it:-

myVar =1 ;

["myVar",5,6] call func ;

func = {

_mv = call compile (_this select 0) ;

} ;

Please note I haven't tested these and they are done from memory so syntax may be a little off.

I admit that they are both a little ugly but I would tend to choose the first solution.

Share this post


Link to post
Share on other sites
I am afraid that's not the point Donnervogel. As said, I just need a way how to pass on global variable names to scripts.

All I get is their values instead when I pass them on. I guess this means no pointers no luck here.

Victor

well it is exactly the point. It is solving your problem in a (slightly) different manner. Instead of passing the variable names to script you would be passing the data (may it be whatever you wish it to be) to specific location that the child processes check for information. You can fully control dynamic numbers of child processes and it's easy too once the system is in place. You have a control script and various executing scripts. Each script can run independently and in many parallel instances. It is just important that the control script keeps track of all running processes so it can pass out the data accordingly.

EDIT: but it is rather complex to set up so if you don't need such flexibility you can pass variable names as strings directly to the scripts as others have suggested.

Share this post


Link to post
Share on other sites

smile_o.gifsmile_o.gifsmile_o.gif

"call" and "compile" indeed do the trick - even though the syntax has slightly changed from OFP. Somehow these commands were not on my radar screen anymore. But it does exactly what I need - convert variable names transferred as strings back into useable code lines throughout multiple script calls.

Still no pointers but a working solution tounge2.gif

Excellent, thanks a lot guys for all your input!

Regards,

Victor

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×