Jump to content
Sign in to follow this  
Rothwell

using variables in trigger statements

Recommended Posts

Hi, I'm setting up a series of bases that will spawn once the player is 300m away from them, and despawn once the player leaves that radius...

I really don't want to hardcode in the .sqf file of each base for it's trigger... this is a matter of making the script generic and saving code.

but here's the problem, I can't pass in local variables like down below, And if I have a global variable, the trigger statement won't take a snapshot of the variable when the trigger's created... it'll grab the value of the variable when the trigger is switched (which will end up being the filename for the last base added to the list)

_templateName = _this select 0; //i.e. "Base1_mission.sqf"
_trig = createTrigger ["EmptyDetector",_location];
_trig setTriggerArea [300,300,0,false];
_trig setTriggerActivation ["ANY","PRESENT",true];
_trig setTriggerStatements ["vehicle player in thislist","hint ""hello there!""; _n = execVM _templateName;","hint ""so long"""];

NOTE: this is just a snippit of my test code.. the whole thing works except the _templateName thing

is there any way to get around writing code for a trigger for every single base?

Share this post


Link to post
Share on other sites

you can't pass local variables to a trigger statement,

try

templateName = _this select 0; //i.e. "Base1_mission.sqf"

_trig setTriggerStatements ["vehicle player in thislist","hint ""hello there!""; null = execVM templateName;","hint ""so long"""];

Share this post


Link to post
Share on other sites

well the problem is, say I have a list of bases, each with their templates, say "base_1.sqf","base_2.sqf"....."base_n.sqf". I will set up a trigger for each one (by calling an init script for each base at the beginning of the mission), but the variable templateName will change with each base, so at the end of all bases, templateName will equal "base_n.sqf", and so when any of the triggers are tripped, "base_n.sqf" will always be called, so I suppose I don't have a choice other than to make some changes so each base has it's own trigger code

Share this post


Link to post
Share on other sites

call compile format is the way forward here. It's clunky and very old fashioned, but used sparingly, it's excellent.

Share this post


Link to post
Share on other sites

Have you tried using setvariable to pass the name?

_templatename= _this select 0; //i.e. "Base1_mission.sqf"

missionNamespace setvariable ["templateName",_templateName];

_trig = createTrigger ["EmptyDetector", getpos place];
_trig setTriggerArea [300,300,0,false];
_trig setTriggerActivation ["ANY","PRESENT",true];
_trig setTriggerStatements ["vehicle player in thislist","hint ""hello there!"";null=[] execvm (missionNamespace getvariable 'templateName')","hint ""so long"""];

Share this post


Link to post
Share on other sites

setvariable is the way forward, I'm sure, though call compile format will work.

Share this post


Link to post
Share on other sites
_templateName = _this select 0; //i.e. "Base1_mission.sqf"
_trig = createTrigger ["EmptyDetector",getPosATL player];
_trig setTriggerArea [300,300,0,false]; 
_trig setTriggerActivation ["ANY","PRESENT",true];
_trig setTriggerStatements ["vehicle player in thislist",format ["player sidechat 'hello there'; 0 = [] execVM '%1.sqf'",_templateName],""];

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  

×