raymix Posted June 18, 2014 Report Share Posted June 18, 2014 quite an annoying one, spent too much time on this... KK demonstrating it on A3 and even Arma wiki stating that: script: String or Code - Either path to the script file, relative to the mission folder, or (since Take On Helicopters) the actual script code. Yet it does not work, even with example provided down below in wiki: player addAction ["Hint Hello!", { hint format ["Hello %1!", _this select 3] }, name player]; I did notice it states code since TKOH, does that mean only Arma 2.5 and 3 supports this? To give you an example, this does not work: _test = player addAction ["Test", {hint"TEST"}]; //nop _test = player addAction ["Test", {hint"TEST"},""]; //nop _test = player addAction ["Test",""]; //works All I want to do is simply change a bool trough addaction without creating a new file just for a single damn line of code, lol Kinda like this: _test = player addAction ["Test",{_check = true}]; Any clues? 31_D!4b10 1 Link to comment Share on other sites More sharing options...
0 Halvhjearne Posted June 18, 2014 Report Share Posted June 18, 2014 it wont work for arma 2, the instructions are mixed with TKOH info that dosnt make much sense and dosnt work for arma 2 either use a scipt to simulate what you intended to do from the addaction then parse the function you want to call/spawn to the script Link to comment Share on other sites More sharing options...
0 raymix Posted June 18, 2014 Author Report Share Posted June 18, 2014 Thanks, I see what you mean. I'll see if I can ping pong between 2 files somehow since I intend to use multiple actions that changes their names depending on variables. Link to comment Share on other sites More sharing options...
0 Halvhjearne Posted June 18, 2014 Report Share Posted June 18, 2014 someone already did this, but i cant find the file now (i think it was called genaction.sqf or something simmular) anyways, the concept was quite simple really, it was basicly a switch using code and arguments parsed through the addaction to the script. im sure you can find it if you search around for it on armaholics. Link to comment Share on other sites More sharing options...
0 raymix Posted June 18, 2014 Author Report Share Posted June 18, 2014 (edited) Cheers, what I simply want to achieve is toggle-able addaction that changes it's name depending on string in variable and is always a top action, kinda like this: myself.sqf _string = (_this select 3); _ok = "on" if (_ok != _string) then { _test = player addaction [format[("<t color=""#ffffff"">" + ("Test: %1") +"</t>"),_string],"myself.sqf","_string = 'on';",6,true,true]; } else { _test = player addaction [format[("<t color=""#ffffff"">" + ("Test: %1") +"</t>"),_string],"myself.sqf","_string = 'off';",6,true,true]; }; I'll report later if this actually works out It works. Script itself can be called, arguments passed works fine with switch, too. Edited June 19, 2014 by raymix Link to comment Share on other sites More sharing options...
0 OtterNas3 Posted June 19, 2014 Report Share Posted June 19, 2014 If not found yet, here is the gen_action.sqf file that u can use for such calls: /* ---Generic Action Script--- Author: [EVO] Curry Function: Enables you to run any code directly from the addAction command Installation: Copy into your missions folder and call this file through addAction Example usage: In init of something this addAction ["Say Hello World!","gen_action.sqf","player sideChat 'Hello World!';"]; Notes: Recommended only for simple code or for testing scripts/functions designed for inits and triggers */ //Parameter one: String or Code - Whatever commands you want to issue, remember to check the syntax ;) private ["_target","_caller","_ID","_arguments"]; _target = _this select 0; _caller = _this select 1; _ID = _this select 2; _arguments = _this select 3; switch (typeName _arguments) do { case "STRING": { nul = [_target,_caller,_ID] spawn (compile _arguments); }; case "CODE": { nul = [_target,_caller,_ID] spawn _arguments; }; default { diag_log text "Error in gen_action.sqf: Invalid type passed to function."; }; }; and here a link to the BIS forum entry for it: http://forums.bistudio.com/showthread.php?98108-addAction-simplified Moo, Otter Link to comment Share on other sites More sharing options...
0 Halvhjearne Posted June 19, 2014 Report Share Posted June 19, 2014 If not found yet, here is the gen_action.sqf file that u can use for such calls: genaction.sqf = gen_action.sqf... thats why i couldnt find it ... lol Link to comment Share on other sites More sharing options...
0 OtterNas3 Posted June 19, 2014 Report Share Posted June 19, 2014 Be advised that this will give hackers the abilty to run any code they like with a call in a script! Not that they can do this anyway but... Link to comment Share on other sites More sharing options...
0 raymix Posted June 19, 2014 Author Report Share Posted June 19, 2014 (edited) Oh, I've seen this one before, thanks. Ended up using something very similar with switch and using addaction to call its own file, where a single argument is being changed that flips the switch removing old action and creating a new one with a little different name and different switch condition - basically toggling multiple addactions within 1 script. I am currently stuck trying to understand forEach tho which basically adds or deletes amount of actions counted in an array. Kinda like how repair vehicle does, but this will be for nearobjects and their snap points array pulled from config file later. Heading to bed now. my brain simply refuses to fix this, been coding on and off all day, lol. edit: just spotted what I did wrong... guess it's another "just 5 more minutes" on this edit2: all working now! Edited June 21, 2014 by raymix Link to comment Share on other sites More sharing options...
0 John Douglas Posted May 22, 2019 Report Share Posted May 22, 2019 Here's a solution I've been working on just this past week, after only having just discovered the AddAction command is broken! The toggle is based upon your assistance and code above. So thanks to "raymix" above for your persistence. I'm only 5 years late and god knows how many hours I've persisted this week. Easily close to 8+ hrs studying and learning code. Below I've now updated my post which demonstrates three versions of using "addAction" command to toggle your captive state. This includes _StringSelect != _toggle_NotEqualOn ; _StringSelect == _toggle_EqualOn ; Case with switch (_StringSelect) do {} , examples: Initialization code included for player, enjoy! /* ////////////////////////////////////////////////////////////////// // Function/Procedure Script file for ArmA2 // Title: toggle_NotEqual.sqf // by JohnDougls, based on raymix script, // https://epochmod.com/forum/topic/12901-addaction-without-external-script ////////////////////////////////////////////////////////////////// // SQF Script: toggle_NotEqual.sqf // // Edit Unit init: // displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_NotEqual.sqf","Off",6,true,true]; /////////////////////////////////////////////////////////////////// */ _StringSelect = (_this select 3); _toggle_NotEqualOn = "On"; /////////////////////////////////////// //1. Off! = On (true) //2. On! = On (false) /////////////////////////////////////// if (_StringSelect != _toggle_NotEqualOn) then { /////////////////////////////////////// // Off != On is true // Set AddAction "Off", having selected "displayAction_on" /////////////////////////////////////// displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_NotEqual.sqf","On",6,true,true]; player setCaptive True; player removeAction displayAction_on; } else { /////////////////////////////////////// // On != On is false // Set AddAction "On", having selected "displayAction_Off" /////////////////////////////////////// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_NotEqual.sqf","Off",6,true,true]; player setCaptive False; player removeAction displayAction_Off; }; _Variable1 = _StringSelect; _Variable2 = _StringSelect; _Variable3 = captive player; Sleep 1; hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3]; Sleep 5; /* ////////////////////////////////////////////////////////////////// // Function/Procedure Script file for ArmA2 // Title: toggle_Equal.sqf // by JohnDougls, based on raymix script, // https://epochmod.com/forum/topic/12901-addaction-without-external-script ////////////////////////////////////////////////////////////////// // SQF Script: toggle_Equal.sqf // // Edit Unit init: // displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true]; /////////////////////////////////////////////////////////////////// */ _StringSelect = (_this select 3); _toggle_EqualOn = "On"; /////////////////////////////////////// //1. On = On (true) //2. Off = On (false) /////////////////////////////////////// if (_StringSelect == _toggle_EqualOn) then { /////////////////////////////////////// // On = On is true // Set AddAction "On", having selected "displayAction_Off" /////////////////////////////////////// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true]; player setCaptive False; player removeAction displayAction_Off; } else { /////////////////////////////////////// // Off = On is false // Set AddAction "Off", having selected "displayAction_on" /////////////////////////////////////// displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_Equal.sqf","On",6,true,true]; player setCaptive True; player removeAction displayAction_on; }; _Variable1 = _StringSelect; _Variable2 = _StringSelect; _Variable3 = captive player; Sleep 1; hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3]; Sleep 5; /* ////////////////////////////////////////////////////////////////// // Function/Procedure Script file for ArmA2 // Title: toggle_Case.sqf // by JohnDougls, based on raymix script, // https://epochmod.com/forum/topic/12901-addaction-without-external-script ////////////////////////////////////////////////////////////////// // SQF Script: toggle_Case.sqf // // Edit Unit init: // displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Case.sqf","Off",6,true,true]; /////////////////////////////////////////////////////////////////// */ _StringSelect = (_this select 3); /////////////////////////////////////// // case "On": // case "Off": // case "default": /////////////////////////////////////// switch (_StringSelect) do { case "On": { /////////////////////////////////////// // case "On": // Set AddAction "On", having selected "displayAction_Off" /////////////////////////////////////// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true]; player setCaptive False; player removeAction displayAction_Off; }; case "Off": { /////////////////////////////////////// // case "Off": // Set AddAction "Off", having selected "displayAction_on" /////////////////////////////////////// displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_Equal.sqf","On",6,true,true]; player setCaptive True; player removeAction displayAction_on; }; default { /////////////////////////////////////// // case "default": // - default block will be executed only if no case matches /////////////////////////////////////// hint "error!" }; }; _Variable1 = _StringSelect; _Variable2 = _StringSelect; _Variable3 = captive player; Sleep 1; hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3]; Sleep 5; Link to comment Share on other sites More sharing options...
Question
raymix
quite an annoying one, spent too much time on this...
KK demonstrating it on A3 and even Arma wiki stating that:
Yet it does not work, even with example provided down below in wiki:
I did notice it states code since TKOH, does that mean only Arma 2.5 and 3 supports this?
To give you an example, this does not work:
All I want to do is simply change a bool trough addaction without creating a new file just for a single damn line of code, lol
Kinda like this:
Any clues?
Link to comment
Share on other sites
9 answers to this question
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now