-Varan 1 Posted May 25, 2020 _variable = _group createUnit ["B_recon_JTAC_F", _position, [], 0, "NONE"]; // _variable = 1; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["this", format ["[%1] spawn _script;", _variable], ""]; Hi, if _variable is an object I get an error message for this code (when setting trigger statements, not when activating the trigger) telling me there is a ] missing. If _variable is a not an object (a number f.e.) everything works fine. What is the matter with this weird behaviour? Share this post Link to post Share on other sites
opusfmspol 282 Posted May 25, 2020 Not sure these are the issue, but: _script is undefined in the expression. Spawn uses function, not script. execVM uses script. Trigger activation must return nothing, and spawn or execVM returns a handle, so might try "nul = [%1] spawn function;" or "nul = [%1] execVM 'folder\script';". Also might try formatting the statement first, then set triggerStatement: _expression = format ["nul = [%1] spawn function;", _variable]; _trigger setTriggerStatements ["this", _expression, ""]; 1 Share this post Link to post Share on other sites
Larrow 2822 Posted May 26, 2020 Objects do not format to string as a usable reference ( unless they have a vehicleVarName ). Instead use BIS_fnc_objectVar or BIS_fnc_netID or save a reference on the trigger using setVariable. _trigger setTriggerStatements ["this", format ["[%1] spawn _script;", _variable call BIS_fnc_objectVar], ""]; Or _trigger setTriggerStatements ["this", format ["[ '%1' call BIS_fnc_objectFromNetID ] spawn _script;", _variable call BIS_fnc_netID], ""]; Or _trigger setVariable[ "var", _variable ]; _trigger setTriggerStatements ["this", "[ thisTrigger getVariable 'var' ] spawn _script;", ""]; And as @opusfmspol points out _script is undefined within the scope of the triggers activation. 1 Share this post Link to post Share on other sites
-Varan 1 Posted May 26, 2020 Spawn uses function, not script. execVM uses script. I use "compile preprocessFile" before "spawn". I read it is the same as "execVM". But thanks for the clue - gonna look over this fact. Trigger activation must return nothing, and spawn or execVM returns a handle, so might try "nul = [%1] spawn function;" or "nul = [%1] execVM 'folder\script';". This error would happen even when _variable is not an object but I'll keep that in mind. Also might try formatting the statement first, then set triggerStatement: _expression = format ["nul = [%1] spawn function;", _variable]; _trigger setTriggerStatements ["this", _expression, ""]; I actually do that to keep the code clean and tidy but obviously the error stays the same. _script is undefined within the scope of the triggers activation. This can't be the case of course, due to the fact that _script runs if _variable is not an object. If _script would be unknown to the scope, it wouldn't run at all. Objects do not format to string as a usable reference ( unless they have a vehicleVarName ). Instead use BIS_fnc_objectVar or BIS_fnc_netID or save a reference on the trigger using setVariable. That's an explanation for this weird behaviour. And I bet that's my problem. I am gonna test it later today and keep you upt to date. Thanks guys. Share this post Link to post Share on other sites
Larrow 2822 Posted May 26, 2020 2 hours ago, -Varan said: _script is undefined within the scope of the triggers activation. This can't be the case of course, due to the fact that _script runs if _variable is not an object. If _script would be unknown to the scope, it wouldn't run at all. It does not run, but fails silently. eg _variable = 1; _script = { hint str _this }; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["true", format ["[%1] spawn _script;", _variable], ""]; Run from a test mission from the debugConsole. You will see no hint as _script is undefined in the triggers activation scope. Replace _script within the triggers activation with the actual code OR make _script a global variable and you will see the hint. _variable = 1; TAG_script = { hint str _this }; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["true", format ["[%1] spawn TAG_script;", _variable], ""]; 1 Share this post Link to post Share on other sites
-Varan 1 Posted May 26, 2020 4 hours ago, Larrow said: It does not run, but fails silently. eg _variable = 1; _script = { hint str _this }; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["true", format ["[%1] spawn _script;", _variable], ""]; Run from a test mission from the debugConsole. You will see no hint as _script is undefined in the triggers activation scope. Replace _script within the triggers activation with the actual code OR make _script a global variable and you will see the hint. _variable = 1; TAG_script = { hint str _this }; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["true", format ["[%1] spawn TAG_script;", _variable], ""]; No - Like I said: The trigger works and runs _script without an error if I pass a variable which is not an object. It's only the type of variable passing into _script causing the error message about missing a ]. Objects do not format to string as a usable reference ( unless they have a vehicleVarName ). This was the problem. Thanks Share this post Link to post Share on other sites
Harzach 2517 Posted May 26, 2020 2 hours ago, -Varan said: The trigger works and runs _script without an error I guess the obvious question now is - what is _script? Something simple like this works: _script = hint "IT WORKS"; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["true", "[] spawn _script;", ""]; but this does not: _script = hint str _this; _variable = 1; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["this", format ["[%1] spawn _script;", _variable], ""]; //returns "[]" and this, as @Larrow explains, does nothing: _script = {hint str _this}; _variable = 1; _trigger = createTrigger ["EmptyDetector", [0,0,0], false]; _trigger setTriggerStatements ["this", format ["[%1] spawn _script;", _variable], ""]; Share this post Link to post Share on other sites
Larrow 2822 Posted May 27, 2020 2 hours ago, Harzach said: Something simple like this works: The trigger still does nothing. You are creating a hint in the first line that you will see when that first line is executed, which returns nothing so _script will be nil. The trigger still fails silently as [ ] spawn nil; is nonsense. 1 Share this post Link to post Share on other sites
Harzach 2517 Posted May 27, 2020 Ah yes, of course. Thanks! Which might be why OP's trigger "works" - _script is just a code block that is being executed before the trigger is created. Share this post Link to post Share on other sites
Larrow 2822 Posted May 27, 2020 6 hours ago, -Varan said: No - Like I said: The trigger works and runs _script without an error Impossible unless you are defining _script within the triggers statement ( which you have not shown ). But if your happy no worries. Share this post Link to post Share on other sites
-Varan 1 Posted May 27, 2020 I didn't post _script to provide a minimal example and because _trigger gets executed without problems if the parameter is not an object but a number or anything simple it is not important for a minimal example. For testing purposes _script took a variable and put it in a hint. It was defined by _script = compile preprocessFile "script.sqf" right before creating the trigger to [_variable] spawn _script. _variable = 3 worked, _variable = createVehicle [...] didn't. But [_variable call BIS_fnc_objectVar] spawn _script works with _variable = createVehicle [...]. I tried to solve the problem on my own for a couple of hours before posting, so I figured already out where exactly the problem occours so I don't have to post my whole script which was 99% fine. Nobody wants to work through a whole script just to find a single object to string parameter problem like mine above 🙂 Share this post Link to post Share on other sites