Home   Help Search Login Register  

Author Topic: how do i refer to a dynamic created variable? (call compile)  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Well, somehow i could also name this topic "local variable in global space problem" but this would be incorrect since i know this isn't allowed. But for a first overview, here's the script that makes me headache.

Code: [Select]
//////////////////////////////////////////////////////////////////
// nul = [this, "ALPHA", "call Iron Eagle"] execVM "STM_AI_CARRIER_SIM\STM_radio_trigger.sqf"
// Created by: -eutf-Myke
// This file will create a radio trigger local
//////////////////////////////////////////////////////////////////

// Edit this part to adjust the squad to your needs
_STM_positions = carrier; // Define either start object or an array with [start, target] objects.
_STM_side = WEST; // Define the side the squad belongs to.
_STM_callsign = "Iron Eagle"; // Define the squad name. Do not use same name for more than one squad.
_STM_flylevel = 400; // Define flight level for squad on approach
_STM_wp_array = []; // Either insert markernames or gamelogic names to set waypoints. Refer to manual for more info.
_STM_veh_array = [["A10", "SoldierWPilot", []], ["A10", "SoldierWPilot", []]]; // Planes in squad. Refer to manual for further infos.
_STM_enemies = [EAST]; // Define one or more sides as enemy to squad.
_STM_waittime = 120; // Define time squad needs to be refueled and rearmed.

// Do not edit anything below this line


_STM_unit = _this select 0;
_STM_radio_channel = _this select 1;
_STM_radio_label = _this select 2;
_STM_carrier = objnull;

_STM_script_array = [_STM_positions, _STM_side, _STM_callsign, _STM_flylevel, _STM_wp_array, _STM_veh_array, _STM_enemies, _STM_waittime, _STM_unit];
if (! (_STM_radio_channel in ["ALPHA", "BRAVO", "CHARLIE", "DELTA", "ECHO", "FOXTROT", "GOLF", "HOTEL", "INDIA", "JULIET"])) exitwith
{
hint format ["%1 is not a valid Radio Channel.\n\nScript STM_radio_trigger.sqf aborted", _STM_radio_channel];
};

if ((typename _STM_positions) == "ARRAY") then
{
_STM_carrier = _STM_positions select 0;
}
else
{
_STM_carrier = _STM_positions;
};
_STM_counter = _STM_carrier getvariable "STM_counter";

call compile format ["STM_script_array%1", _STM_counter] = _STM_script_array;

_STM_trg=createTrigger["EmptyDetector", [0, 0, 0]];
_STM_trg setTriggerArea[0,0,0,false];
_STM_trg setTriggerActivation[_STM_radio_channel,"PRESENT",true];
_STM_trg setTriggerStatements["this", "nul = _STM_script_array execVM 'STM_AI_CARRIER_SIM\STM_air_carrier.sqf'", ""];
_STM_trg setTriggertext _STM_radio_label;

_STM_counter = _STM_counter + 1;
_STM_carrier setVariable ["STM_counter", _STM_counter];

The problem starts at the line with setTriggerStatement as i want to pass a local array to the scriptcall for the on activation part.
As you know, this will cause the above stated error message "local variable in global space" which i understand.

To make the problem worse, i would try to avoid to use same arrayname twice to avoid interferences if the script is called twice at the same time (i doubt this would happen but i like to make it idiot proof).

So i've searched the forum and i found some topics in which i read to use call compile format to create dynamicly changing variable/array names. So i've adapted this way and you'll find the line just above the createtrigger line.

Now my problem arises: In the on activation line, how do i refer to this array without using a local variable/array name?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: how do i refer to a dynamic created variable? (call compile)
« Reply #1 on: 24 Apr 2008, 00:52:57 »
Why not to use a global array?

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: how do i refer to a dynamic created variable? (call compile)
« Reply #2 on: 24 Apr 2008, 00:57:37 »
Indeed, thinking about it, i really doubt that the script will run twice with different settings at the same time, messing it up. I'm sorry, i was making things more complicated than they were.

Why makin it easy if it's possible to do it complicated.  :D


So, *SOLVED*

And as this topic is completely obsolete, mods/admins might delete it completely.