Jump to content
Sign in to follow this  
Rothwell

Using setVariable / getVariable with triggers

Recommended Posts

Hi, I am wondering if it is possible to store variables with triggers; I have a 2D array with triggers and other info whose indexes correspond with another array of locations.

say I have 3 locations... row 1 represents the locations array, row 2 represents the triggers array

[table=width: 500]

[tr]

[td]loc1[/td]

[td]loc2[/td]

[td]loc3[/td]

[/tr]

[tr]

[td][trigger east, trigger west, east present?, west present?][/td]

[td][trigger east, trigger west, east present?, west present?][/td]

[td][trigger east, trigger west, east present?, west present?][/td]

[/tr]

[/table]

here is the code where I initialize the array containing the triggers

for[{_x = 0},{_x < count Spawns},{_x = _x + 1}] do
{
//[trigger east, trigger west, east present, west present]
_eTrig = createTrigger["EmptyDetector", getMarkerPos (Spawns select _x)];
_eTrig setVariable["index", _x];
_eTrig setTriggerArea[15,15,0,false];
_eTrig setTriggerActivation["EAST","PRESENT",true];
_eTrig setTriggerStatements[ "this" , 
	"_x = _this getVariable ""index"";
	hint format[""%1"",_x];                       //PRINTS "any" WHEN TRIGGER IS ACTIVATED!!
	_temp = Spawn_Trigs select _x;
	_temp set [2, true];
	Spawn_Trigs set [_x, _temp];" ,
	"_x = _this getVariable ""index"";
	_temp = Spawn_Trigs select _x;
	_temp set [2, false]; 
	Spawn_Trigs set [_x, _temp];" 
	];

_wTrig = createTrigger["EmptyDetector", getMarkerPos (Spawns select _x)];
_wTrig setVariable["index", _x];
_wTrig setTriggerArea[15,15,0,false];
_wTrig setTriggerActivation["WEST","PRESENT",true];
_wTrig setTriggerStatements[ "this" , 
	"_x = _this getVariable ""index"";
	_temp = Spawn_Trigs select _x; 
	_temp set [3, true]; 
	Spawn_Trigs set [_x, _temp];" , 
	"_x = _this getVariable ""index"";
	_temp = Spawn_Trigs select _x; 
	_temp set [3, false]; 
	Spawn_Trigs set [_x, _temp];" 
	];


Spawn_Trigs set[_x, [_eTrig,_wTrig,false,false]];
hint format["%1",((Spawn_Trigs select _x) select 0) getVariable "index"]; //prints correct index when initializing the triggers
sleep .5;
};

Share this post


Link to post
Share on other sites

It is possible to store variables for triggers.

Try using thisTrigger instead of _this

So

"_x = thisTrigger getVariable ""index"";

I would however recommend running a script from the onAct field instead of coding everything there :).

Edited by cuel

Share this post


Link to post
Share on other sites

I don't think you can use _temp in a trigger as it's a local variable.

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  

×