juleshuxley   9 Posted October 12, 2020 I want to run a function before EVERY mission. This is a QOL addon, not a scenario. I do not want the CBA dependency for something that should be so simple. I've spent 8 hours trying to get fn_myFunction to run when a mission is started. 🙃🙃🤬 This is the structure of my mod: This is the contents of config.cpp: class CfgPatches{ class SinglePlayerCharacterSwitcher{ author = "CaptainDucko"; version = 1.0; units[]={}; weapons[]={}; requiredAddons[]={}; requiredVersion = 0.1; }; }; class CfgFunctions { class myTag { class myCategory { class myFunction {}; }; }; }; This is the result: 🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬 WHY IT'S RIGHT HERE Sorry but 8 hours trying backslashes, forward slashes, changing directory structures, building, building, building I'm going insane. Share this post Link to post Share on other sites
maihym   12 Posted October 12, 2020 https://community.bistudio.com/wiki/Arma_3_Functions_Library#Attributes Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 3 minutes ago, maihym said: https://community.bistudio.com/wiki/Arma_3_Functions_Library#Attributes dude my screenshots depict the example shown under "Default Path (Mission Only)". I've tried every example and nothing works I have no idea what I'm missing Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 Second example from that page just just does not work!!!! Structure: Config: class CfgPatches{ class SinglePlayerCharacterSwitcher{ author = "CaptainDucko"; version = 1.0; units[]={}; weapons[]={}; requiredAddons[]={}; requiredVersion = 0.1; }; }; class CfgFunctions { class myTag { class myCategory { class myFunction {file = "myFile.sqf";}; }; }; }; ERROR: 😡 Share this post Link to post Share on other sites
RCA3 Â Â 593 Posted October 12, 2020 This will try to compile function myTag_fnc_myFunction from the following file: %ROOT%\myFile.sqf Are you calling the function as in bold statement? i.e.: call myTag_fnc_myFunction; Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 I'm writing `call myTag_fnc_myFunction` in the console. But I get the Script myFile.sqf not found error when I start up Arma, before I start a mission / scenario in the editor Share this post Link to post Share on other sites
RCA3   593 Posted October 12, 2020 But the function works? All I can say is add this to requiredAddons, if the function works and this doesn't help I don't know. requiredAddons[]={"A3_Data_F_Enoch_Loadorder"}; Wait... what is this? Remove that. Nevermind it's your addon name 😑 2 hours ago, juleshuxley said: class SinglePlayerCharacterSwitcher{  Try giving it a name name = "Your mod name"; And not sure version should be there. https://community.bistudio.com/wiki/CfgPatches  The function not working, might be an error on the function. Debug it to RPT first with just one command. diag_log Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 No the fuction doesn't work, I'll trt that requiredAddons, thank you 1 Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 Doesn't work. ridiculous. such weak documentation. ive tried every example on that page. thanks for trying though 1 Share this post Link to post Share on other sites
RCA3 Â Â 593 Posted October 12, 2020 You need to pass your addon folder name first: class myFunction {file = "SinglePlayerCharacterSwitcher\myFile.sqf";}; Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 Here is the structure of my project. It contains just two files, config.cpp and myFile.sqf: config.cpp: class CfgPatches{ class Test{ author = "CaptainDucko"; name = "S P C S"; units[]={}; weapons[]={}; requiredAddons[]={"A3_Data_F_Enoch_Loadorder"}; requiredVersion = 0.1; }; }; class CfgFunctions { class myTag { class myCategory { class myFunction {file = "\myFile.sqf";}; }; }; }; myFile.cpp: myTag_fnc_myFunction = { _returnThis = "doesnt_work"; _returnThis; }; When I start Arma 3, I get this error: Why? I have changed the file attribute to "file = myFile.sqf" and "file = /myFile.sqf" but I get the same error message every time. Share this post Link to post Share on other sites
RCA3 Â Â 593 Posted October 12, 2020 Read above. This case would be: class myFunction {file = "test\myFile.sqf";}; Btw works both with "\test\..." or "test\..." Â 1 hour ago, juleshuxley said: myFile.cpp: myTag_fnc_myFunction = { _returnThis = "doesnt_work"; _returnThis; }; Â I think you mean myfile.sqf and that's not how it works. You don't redefine the function inside the file, it's already defined at this point. Â Just type the commands you want to call immediately. As a test use this: Â myfile.sqf: systemChat "hello"; Â And your folder organization should be: @test-master\addons\test\ Share this post Link to post Share on other sites
maihym   12 Posted October 12, 2020 Try this just replace "modFolderName" with the name of the folder your mod is in. To call the function you would use [] call fnc_myFunction; if calling from another file or SQF but the preInit will launch the script when the mod gets loaded in. class CfgPatches{ class SinglePlayerCharacterSwitcher{ author = "CaptainDucko"; version = 1.0; units[]={}; weapons[]={}; requiredAddons[]={}; requiredVersion = 0.1; }; }; class CfgFunctions { class myCategory { file = "modFolderName\myCategory"; class myFunction{ preInit = 1; }; }; };  1 Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 I must be dumb. nothing works, im going to bed  Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 24 minutes ago, maihym said: Try this just replace "modFolderName" with the name of the folder your mod is in. To call the function you would use [] call fnc_myFunction; if calling from another file or SQF but the preInit will launch the script when the mod gets loaded in. class CfgPatches{ class SinglePlayerCharacterSwitcher{ author = "CaptainDucko"; version = 1.0; units[]={}; weapons[]={}; requiredAddons[]={}; requiredVersion = 0.1; }; }; class CfgFunctions { class myCategory { file = "modFolderName\myCategory"; class myFunction{ preInit = 1; }; }; };  Where is the reference to myFile.sqf . And what's myCategory? Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 this is so dumb. I've created a really complicated mod, but it's in script form for one of my eden projects. I've done the hard bit. It works. Now I just need to package it into a addon and have an initialization function fire on mission start. That's it. Insane. Day wasted. In a C++ project, init.cpp is always run first. In a website, index.html is opened first. In Arma 3?!?! god only knows how you create an init script. Share this post Link to post Share on other sites
RCA3   593 Posted October 12, 2020 Google Drive Example  I forgot you got to call myTag_fnc_myFunction on debug console. 1 Share this post Link to post Share on other sites
maihym   12 Posted October 12, 2020 8 minutes ago, juleshuxley said: this is so dumb. I've created a really complicated mod, but it's in script form for one of my eden projects. I've done the hard bit. It works. Now I just need to package it into a addon and have an initialization function fire on mission start. That's it. Insane. Day wasted. In a C++ project, init.cpp is always run first. In a website, index.html is opened first. In Arma 3?!?! god only knows how you create an init script.  Try my code in your original post format. "myCatergory" is the folder and "myFunction" is the filename. If a file is named "fn_myFunction.sqf" then arma will know to make that file a function. Paste my code into your config.cpp file and it should work. 1 Share this post Link to post Share on other sites
juleshuxley   9 Posted October 12, 2020 16 hours ago, RCA3 said: Google Drive Example  I forgot you got to call myTag_fnc_myFunction on debug console. Thank you for your example it was invaluable. This stuff is simple but very fiddly for a beginner imho. Thankyou maihym. My mod is working!! 1 Share this post Link to post Share on other sites
maihym   12 Posted October 12, 2020 1 hour ago, juleshuxley said: Thank you for your example it was invaluable. This stuff is simple but very fiddly for a beginner imho. Thankyou maihym. My mod is working!! xD it's been a while since I've worked with Arma 3 but it's nice to know that I've still got it Share this post Link to post Share on other sites