Jump to content
Sign in to follow this  
Grumpy Old Man

Initialization Order - Defining variables

Recommended Posts

Hey folks,

 

been scratching my head about this.

I got a function called GOM_fnc_Init.sqf, defined as a function in my function library:

GOM_var_test = "test";

Now when I call it from init.sqf either in MP or SP the variable is defined and all is in working order.

If I remove the function call from init.sqf and try to use the additional parameters like preInit, postInit, preStart to automatically call the function (in description.ext CfgFunctions), the variable stays undefined, no matter what.

 

Is there any way to define variables in functions called with the preInit, postInit or preStart parameters?

Looks like it would be a good way to run CPU intensive tasks before the mission start, just can't get it to work (running Apex Sneak Preview).

 

Cheers

Share this post


Link to post
Share on other sites

It should always work.

If a function is executed via preInit=1 or postInit=1 this function is being executed either prior or past mission start. That makes these variables "visible" as well. Functions called like this will be called both on server and client so it shouldn't be a problem of locality.

Recently I found a mod that prevented postinit=1-functions to be executed on dedicated server. Maybe it's some sort of problem like that?

 

Upload your mission to dropbox or something like that and we could take a look at it.

Share this post


Link to post
Share on other sites

description.ext:

class CfgFunctions
{
	#include "functions\cfgFunctions.hpp"
};

cfgFunctions.hpp:

class GrumpyOldManFunctions
{
	tag = "GOM"; // Functions tag.  Functions will be called as [] call GOM_fnc_whatever
	
	class initialValues 
	{
		class iv {
			file = "functions\fn_initialValues.sqf";
			description  = "initial values";
			preInit = 1;
		};
	};
	
	class functions
	{
		file = "functions"; // Folder where individual function files are stored.
		class whatever {}; // functions\fn_whatever.sqf
	};
};

functions\fn_initialValues.sqf:

missionNamespace setVariable ["popcorn", "yummy", true];
diag_log "It is official, popcorn is yummy as of now!";

Then from gamestart or just popcorn:

rszAQSE.jpg

Share this post


Link to post
Share on other sites

Just noticed my error, I had it like this:

class CfgFunctions
{
    class GOM
    {

        class test

        {
            class variableTest{file = "scripts\GOM_fnc_varTestpreInit.sqf"};
            preInit = 1;
        }

    }

};

instead of this:

class CfgFunctions
{
    class GOM
    {

        class test

        {
            class variableTest{file = "scripts\GOM_fnc_varTestpreInit.sqf";
            preInit = 1;

            };
        }

    }

};

Need a drink now.

 

Cheers

Share this post


Link to post
Share on other sites

Your PreInit=1 are outside their class declarations.

 

Change it to:

class variableTestpreInit{file = "scripts\GOM_fnc_varTestpreInit.sqf";preInit = 1;};
			
  • Like 2

Share this post


Link to post
Share on other sites

defining variables isn't really too CPU intensive. Of course it's better to define before clients are in the game (who would notice the stutter as large variables are defined in namespace), but even init.sqf is sufficient for this.

Share this post


Link to post
Share on other sites

defining variables isn't really too CPU intensive. Of course it's better to define before clients are in the game (who would notice the stutter as large variables are defined in namespace), but even init.sqf is sufficient for this.

If you want the variables available for object init fields you'll want to preinit them like this.  Init.sqf runs after init fields.

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  

×