Jump to content
Sign in to follow this  
juleshuxley

Call a function via config.cpp

Recommended Posts

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:
mod.jpg
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:
error.jpg


🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬🤬
WHY IT'S RIGHT HERE

fu.jpg

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

Second example from that page just just does not work!!!!
Structure:
structure2.jpg
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: 😡

error2.png

Share this post


Link to post
Share on other sites

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

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

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

Doesn't work.  ridiculous. such weak documentation. ive tried every example on that page. thanks for trying though

  • Confused 1

Share this post


Link to post
Share on other sites

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

Here is the structure of my project. It contains just two files, config.cpp and myFile.sqf:

structure99.jpg

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:
error77.png

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

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

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;
        };
    };
};

 

  • Like 1

Share this post


Link to post
Share on other sites
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

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
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.

  • Like 1

Share this post


Link to post
Share on other sites
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!!

  • Like 1

Share this post


Link to post
Share on other sites
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×