Thrash 0 Posted June 11, 2008 Hi all, I've been playing around (while i should be studying) with a script which dynamically creates triggers based on an array of positions. Its all working fine (the triggers are creating), but i cant seem to give each one it's own activation statement (dynamically). This is the code: note: tName, tPosX... etc.... are vars which change with every loop of the 'for' statement... which creates the triggers. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> call compile format ["TRG%1 = Â createTrigger [""EmptyDetector"", [tPosX,tPosX]]",tName]; call compile format ["TRG%1 setTriggerArea[(tSize),(tSize),0,false]",tName]; call compile format ["TRG%1 setTriggerActivation[""WEST"",""PRESENT"",true]",tName]; call compile format ["TRG%1 setTriggerStatements[""this"",""nil = [%1] execVM 'IL_Scripts\ScriptName.sqf'"", """"]",tName]; It's the last line that's the problem. Which ever trigger i activate, it calls "nil = [%1] execVM 'IL_Scripts\ScriptName.sqf" but 'nil' is always set to the last trigger created... with 'tName' set to the last tName used(accessed by the loop). What i want to do is dynamically set the var name ( in this case 'nil' ) to be a unique name, and the 'tName' var to also be unique for each trigger.... so that every trigger created has it's own unique activation field, and sends different parameters to the script it calls. The only way i can think of is to have a nested 'call compile format' within the outer 'call compile format'. but i cant seem to get it working. eg: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> call compile format ["TRG%1 setTriggerStatements[""this"",""call compile format[""""TrgVar%1 = [%1] execVM 'IL_Scripts\ScriptName.sqf'"""",tName]"", """"]",tName]; Does anyone know how i can do this, or any other way of getting a unique var to a script from a dynamically created trigger?? Share this post Link to post Share on other sites
kronzky 5 Posted June 11, 2008 Your first method looks correct, as far as the syntax is concerned, but I think the only problem is that the variable tName you're putting into the argument of the script call (the <span style='color:blue'>nil = [%1] execVM 'IL_Scripts\ScriptName.sqf'</span>) is probably just a number, whereas the name of the trigger is TRG, plus a number (i.e. TRG1, TRG2, ...). So, if you change your statement code to <span style='color:blue'>nil = [TRG%1] execVM 'IL_Scripts\ScriptName.sqf'</span> it should probably work. I tried the code below, and that put out a different number for each trigger I enter:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for "_i" from 1 to 3 do { tName=str(_i); tPosX=getPos player select 0; tPosY=(getPos player select 1)+50*_i; tSize=20; call compile format ["TRG%1 = Â createTrigger ['EmptyDetector', [tPosX,tPosY]]",tName]; call compile format ["TRG%1 setTriggerArea[(tSize),(tSize),0,true]",tName]; call compile format ["TRG%1 setTriggerActivation['WEST','PRESENT',true]",tName]; call compile format ["TRG%1 setTriggerStatements['this','hint str(%1)', '']",tName]; }; Share this post Link to post Share on other sites
Thrash 0 Posted June 11, 2008 Yeah i've tried that too. It's possible to use 'hint' with a variable, Â but not possible to send the variable to a script via the [%1]execVM.... etc. I dont know why. although i am very tired, so i might be over looking something....plus i've never written much arma code before, so that doesnt help. The var 'tName' is actually the town name which the trigger is created over, so it'll be a string, like 'Paraiso'.... I might try using str(), which you've used, and see if creating a string inside the 'call compile format' works. because at the moment, every instance of 'nil = [] execVM...blah' is being overwritten by the next instance, so i'm only ever getting the last instance of 'nil = [] execVM...blah' created. Using 'hint str(%1)', it creates an instance of the hint command in the trigger field when the trigger is created. but using the 'nil = [] execVM...blah' command, it's creating a variable which keeps on being overridden... now i'm repeating myself...ha, i'm confused. Oh well, nothing a scotch cant fix. Share this post Link to post Share on other sites
shinRaiden 0 Posted June 11, 2008 Your first method looks correct, as far as the syntax is concerned, but I think the only problem is that the variable tName you're putting into the argument of the script call (the <span style='color:blue'>nil = [%1] execVM 'IL_Scripts\ScriptName.sqf'</span>) is probably just a number, whereas the name of the trigger is TRG, plus a number (i.e. TRG1, TRG2, ...).So, if you change your statement code to <span style='color:blue'>nil = [TRG%1] execVM 'IL_Scripts\ScriptName.sqf'</span> it should probably work. I tried the code below, and that put out a different number for each trigger I enter:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for "_i" from 1 to 3 do { tName=str(_i); tPosX=getPos player select 0; tPosY=(getPos player select 1)+50*_i; tSize=20; call compile format ["TRG%1 = createTrigger ['EmptyDetector', [tPosX,tPosY]]",tName]; call compile format ["TRG%1 setTriggerArea[(tSize),(tSize),0,true]",tName]; call compile format ["TRG%1 setTriggerActivation['WEST','PRESENT',true]",tName]; call compile format ["TRG%1 setTriggerStatements['this','hint str(%1)', '']",tName]; }; Uh, before you go setting nil to a non-nil value, and get your legs gnawed off (or worse) by gypsie for doing that, don't. Nil is supposed to be used the other way around, ie <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">VarToNuke = nil; instead of <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">nil = VarOverWritingPubVarNamedNil; Use your own bucket, preferably a disposable private var instead. Share this post Link to post Share on other sites
Thrash 0 Posted June 11, 2008 ok cheers for that heads up... but what i'm trying to do is exactly what you mentioned. I'm trying to create my own 'nil' inside the 'call compile format', on the fly. eg. when it calls the 'compile format' i want it to create a new/unique 'nil' and a new/unique function parameter for each trigger. Share this post Link to post Share on other sites
kronzky 5 Posted June 11, 2008 Well, you cannot actually pass the trigger object, since it's not really contained in your tName variable. That only contains *part* of the trigger's name, but not the trigger object itself. All you're really passing to the script would be the name of the trigger (or part of that name). But since you're familiar with the call compile concept it's fairly straightforward to then get the actual trigger *object* from that in your script. So, if you call your script like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call compile format ["TRG%1 setTriggerStatements['this','nul=[""TRG%1""] execVM ""tst.sqf""', '']",tName]; and the script itself contains something like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_name = _this select 0; _trg = call compile format["%1",_name]; _pos = getPos _trg; player sidechat format["arg:%1, pos:%2",typename _trg,_pos]; you will end up with the trigger object in your script (as seen by reading its position). And, of course, ShinRaiden is right, in that you shouldn't really use "nil" to dump stuff into. It's not going to break anything per se, but if you should ever forget that you overwrote nil with your own value, and later use it to empty a variable, you might be in for a surprise. Actually, that behavior has recently changed, in that you can't overwrite commands anymore, but I'm not quite sure if this was only done in VBS, or in ArmA as well, so better play it safe... ;) Share this post Link to post Share on other sites
Thrash 0 Posted June 11, 2008 Thanks a lot mate, it's working. I was over complicating things as is often the case in scripting, trying to nest compiles within compiles etc.. and couldn't see the simplicity of it. I guess i just needed that outside help from a person who hadn't seen the script a million times. Thanks again. Share this post Link to post Share on other sites
FunkD00BiesT 10 Posted August 2, 2009 (edited) Thanks guys this is exacly what I was strugling with, getting dynamic names for triggers as well as setting dynamic Statements in the triggers wich I did by a more simple way but did not get the triggers to work at all lol. But I also did not get any errors in the report, Sample code:{ _TriggerArray = ["((this) and ((getmarkerColor " + (HP select _a) + ") == ""ColorGreen""))",((HP select _a) + " setmarkercolor ""ColorGreen""; Player sidechat ""US has captured " + str(HP select _a) + "."";"),""]; Trigger setTriggerStatements _TriggerArray; } But I'm not sure why all <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call compile format ["TRG%1 setTriggerStatements['this','nul=[""TRG%1""] execVM ""tst.sqf""', '']",tName]; Is nessesary? I've found that the format method is allot easyer to use so doing string math as i've done above is not really the best way to go, any one using that method should really give format a try. Edited August 9, 2009 by FunkD00BiesT Question Nullified. Share this post Link to post Share on other sites