dreadedentity 278 Posted January 29, 2016 Hello! It has been a long time since I have made a code snippet! I am going to start making a GUI tutorial soon (maybe a series) but I don't like several of the things I had to do when I started learning about GUI's in Arma. Like many, I read and followed Iceman77's guide (and even had the privilege of having him in my teamspeak server multiple times), and bangabob's video tutorial. However, these required you to download/copy some files that had been already created for you. For a long time while I was learning, I did not realize the freedom that was available to me. Of course, a fair amount of my misunderstanding was probably due to naivete with the engine. However, in my tutorial series I want to express how much freedom one has and teach people not to be scared of searching for information and trying new things, not just follow a guide. So to prevent having to provide some file(s) that won't teach the viewer anything, I wanted to write a function that will allow them to "export" a config straight from the game, using BIS's default values. Note: This function must be compiled using the functions library with the Tag "DREAD" and the name "copyConfigClass" to work properly. As it is a recursive function, if you want to compile it with a different name, you will have to edit the self-call within the function yourself. The easiest way to use this script is to compile it using the functions library, using the names I have listed previously. So without further delay, here's my script:fn_copyConfigClass.sqf /////////////////////////////////////// // Function file for Armed Assault 3 // // Created by: DreadedEntity // // // // MUST BE COMPILED WITH THE // // FUNCTIONS LIBRARY // //Tag = DREAD Name = copyConfigClass// /////////////////////////////////////// /* TO USE: _partialClass = [config] call DREAD_fnc_copyConfigClass; INPUT: config: TYPE - Config | Anything that is not a config class is rejected. OUTPUT: _partialClass: TYPE - STRING | USED BY THE FUNCTION TO CREATE OUTPUT, DO NOT OVERWRITE HOWEVER, it is possible to save the result outside of the function, to run it multiple times ex. _textBoxClass = [configFile >> "RscText"] call DREAD_fnc_copyConfigClass; _listBoxClass = [configFile >> "RscListBox"] call DREAD_fnc_copyConfigClass; _buttonClass = [configFile >> "RscButton"] call DREAD_fnc_copyConfigClass; TO CLIPBOARD: Outputs a full class definition, even returning subclasses and their attributes, and it's nicely formatted with tabs. I'm such a god. */ private ["_parents","_numTabs","_numParams","_param","_newConfig","_params"]; _MAKE_TABS = { _tabs = ""; for "_t" from 1 to _this do { _tabs = _tabs + (toString [9]); }; _tabs; }; if (!isClass (_this select 0)) exitWith {"Input Was Not A Class"}; _newLine = toString [13, 10]; _parents = [_this select 0] call BIS_fnc_returnParents; _numTabs = _this param [1, 0, [0]]; _output = _this param [2, "", [""]]; _output = _output + (_numTabs call _MAKE_TABS) + "class " + (configName (_this select 0)) + _newLine + (_numTabs call _MAKE_TABS) + "{" + _newline; _params = []; { _numParams = (count _x) - 1; for "_i" from 0 to _numParams do { _param = configName (_x select _i); _newConfig = (_this select 0) >> _param; if (isClass _newConfig) then { _output = [_newConfig, _numTabs + 1, _output] call DREAD_fnc_copyConfigClass; } else { _newParam = _param; _data = nil; switch (true) do { case (isNumber _newConfig): { _data = getNumber _newConfig; }; case (isText _newConfig): { _data = str(getText _newConfig); }; case (isArray _newConfig): { _newParam = _newParam + "[]"; _data = str(getArray _newConfig); _data = "{" + (_data select [1, (count _data) - 2]) + "}"; }; }; if (_params find _param == -1) then { _output = _output + ((_numTabs + 1) call _MAKE_TABS) + format["%1 = %2;%3", _newParam, _data, _newLine]; _params pushBack _param; }; }; }; } forEach _parents; _output = _output + (_numTabs call _MAKE_TABS) + "};" + _newline; copyToClipboard _output; _output; Lastly, I'd like to thank the person who wrote the code for the Splendid Config Viewer; whose code was so bloated and unreadable I experienced the greatest headache of my life from reading it, and probably got cancer. 3 Share this post Link to post Share on other sites
barbolani 198 Posted January 29, 2016 That's why I am dialog retarded, I care about my health... I really wait with expectation those tuts. My dialogs are near shit. Share this post Link to post Share on other sites
das attorney 858 Posted January 29, 2016 On 1/29/2016 at 7:41 AM, dreadedentity said: As it is a recursive function, if you want to compile it with a different name, you will have to edit the self-call within the function yourself. Ha, that bring back memories of the TS channel and recursive functions - always with the private array! ;) Good job there mate :) Share this post Link to post Share on other sites
moricky 211 Posted January 29, 2016 On 1/29/2016 at 7:41 AM, dreadedentity said: Lastly, I'd like to thank the person who wrote the code for the Splendid Config Viewer; whose code was so bloated and unreadable I experienced the greatest headache of my life from reading it, and probably got cancer. You're welcome ;) Honestly, trying to replicate tree structure in a listbox gave me headaches too (this is long before commands for tree operations were introduced). 1 Share this post Link to post Share on other sites
jshock 513 Posted January 29, 2016 On 1/29/2016 at 12:30 PM, das attorney said: Ha, that bring back memories of the TS channel and recursive functions - always with the private array! ;) Good job there mate :) Oh the good ol' days of the Scripters' Lounge, learned a lot and had some fun along with it :D. Share this post Link to post Share on other sites
das attorney 858 Posted January 29, 2016 On 1/29/2016 at 5:16 PM, jshock said: Oh the good ol' days of the Scripters' Lounge, learned a lot and had some fun along with it :D. Is SL dead now? I was thinking about it the other day, if it's still going, let me know the login - would be good to catch up with you guys again :) Share this post Link to post Share on other sites
dreadedentity 278 Posted January 29, 2016 On 1/29/2016 at 10:08 AM, barbolani said: That's why I am dialog retarded, I care about my health... I really wait with expectation those tuts. My dialogs are near shit. Going to start soon! On 1/29/2016 at 12:57 PM, moricky said: You're welcome ;) Honestly, trying to replicate tree structure in a listbox gave me headaches too (this is long before commands for tree operations were introduced). It really was a headache trying to understand what was going on! The bit about cancer was more tongue-in-cheek :P . You always take shots in stride though. I do have one question for you, I think I have noticed a few scripts/functions of yours that are written recursively with a unique parameter and a switch for functionality. Is there any reason you make them this way? Any other benefits other than keeping the code to one file? On 1/29/2016 at 5:33 PM, das attorney said: Is SL dead now? I was thinking about it the other day, if it's still going, let me know the login - would be good to catch up with you guys again :) I'm always in one teamspeak or another, PM me, I'd love to chat sometime Share this post Link to post Share on other sites