bangabob 45 Posted July 22, 2014 Hello guys. Got a small problem with my script. I am trying to create a system that manipulates markers and part of this involves passing a condition into the script. For example null=["mkr","!alive obj1",[]] execVM "script.sqf"; Script.sqf _mkr=(_this select 0); _task=(_this select 1); while {true} do { if (_task) then {//code here}; sleep 0.5; }; Btw i know i can send the code using {} brackets. But then this doesn't work with "if" statements. So my question is how can i retrieve code from my script call. I have looked into string manipulation to remove the "" but this is all a little above me. Thanks for reading Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted July 22, 2014 (edited) null = ["mkr",{if (!alive obj1) then {true} else {false};},[]] execVM "script.sqf"; Perhaps something like that. Alternative would be to sort out the bool beforehand and contain it in a variable... private ["_condition"]; _condition = false; if (!alive obj1) then { _condition = true; }; null = ["mkr",_condition,[]] execVM "script.sqf"; Edited July 22, 2014 by MDCCLXXVI Share this post Link to post Share on other sites
bangabob 45 Posted July 22, 2014 null = ["mkr",{if (!alive obj1) then {true} else {false};},[]] execVM "script.sqf"; Perhaps something like that. Alternative would be to sort out the bool beforehand and contain it in a variable... private ["_condition"]; _condition = false; if (!alive obj1) then { _condition = true; }; null = ["mkr",_condition,[]] execVM "script.sqf"; This is not really what i am looking for because i already use a very similar method as a workaround. Specifically i want to extract the code from the string by removing the "". Is this even possible? Share this post Link to post Share on other sites
SilentSpike 84 Posted July 22, 2014 (edited) compile sounds like what you're looking for So: if (compile _task) then {//code here}; Nevermind, that outputs code (aka {}). Edited July 22, 2014 by SilentSpike Share this post Link to post Share on other sites
cuel 25 Posted July 22, 2014 Did you try to return something from the code and then execute it? null=["mkr",{_cond = !alive obj1; _cond},[]] execVM "script.sqf"; _mkr=(_this select 0); _task=(_this select 1); while {true} do { if (call _task) then {//code here}; sleep 0.5; }; Share this post Link to post Share on other sites
bangabob 45 Posted July 22, 2014 (edited) Did you try to return something from the code and then execute it? null=["mkr",{!alive obj1; _cond},[]] execVM "script.sqf"; _mkr=(_this select 0); _task=(_this select 1); while {true} do { if (call _task) then {//code here}; sleep 0.5; }; Cool, that works. Im half asleep so i am probably missing something obvious but is there a way to have the {!alive obj1;_cond} bit inside the sqf file rather than the script call Something like null=["mkr",{_cond = !alive obj1;},[]] execVM "script.sqf"; _mkr=(_this select 0); _task=(_this select 1); // special way here while {true} do { if (call _task) then {//code here}; sleep 0.5; }; Edited July 22, 2014 by BangaBob Share this post Link to post Share on other sites
fight9 14 Posted July 22, 2014 (edited) Call compile can turn string to code without the brackets. call compile format ["_obj = %1",_varname]; is the same as _obj = _varname; Edited July 22, 2014 by Fight9 Share this post Link to post Share on other sites
SilentSpike 84 Posted July 22, 2014 Call compile can turn string to code without the brackets. call compile format ["_obj = %1",_varname]; is the same as _obj = _varname; You have to call it though because it is a code snippet (aka, has brackets). So it doesn't work in an if statement unless it's returning a boolean Share this post Link to post Share on other sites
bangabob 45 Posted July 22, 2014 Ive got it. Simple really. null=["mkr","!alive obj1"] execVM "script.sqf"; Script.sqf _mkr=(_this select 0); _task=(_this select 1); while {true} do { if (call compile _task) then {//code here}; sleep 0.5; }; I used call compile in the if statement. Turns a string into code. Share this post Link to post Share on other sites
tomturner 10 Posted July 22, 2014 Just remove the "" from around !alive obj1. null=["mkr",!alive obj1,[]] execVM "script.sqf"; Share this post Link to post Share on other sites
SilentSpike 84 Posted July 22, 2014 Just remove the "" from around !alive obj1. Surprised none of us even noticed this sooner :p Share this post Link to post Share on other sites
IndeedPete 1038 Posted July 22, 2014 Ive got it. Simple really. null=["mkr","!alive obj1"] execVM "script.sqf"; Script.sqf _mkr=(_this select 0); _task=(_this select 1); while {true} do { if (call compile _task) then {//code here}; sleep 0.5; }; I used call compile in the if statement. Turns a string into code. You could optimise it a bit by compiling it one time and then just calling it: _mkr=(_this select 0); _task=(_this select 1); _cond = compile _task; while {true} do { if (call _cond) then {//code here}; sleep 0.5; }; It's a bit cleaner since it doesn't force the engine to recompile it on each iteration. Or you could pass it already as code {} as someone mentioned before. ---------- Post added at 07:09 PM ---------- Previous post was at 07:07 PM ---------- Removing the "" will just result in a one-time-only evaluation which is not what he was looking for if he runs the condition stuff in a loop I guess. But I might be wrong, didn't test it. Share this post Link to post Share on other sites