Jump to content
Extremist79

Defined symbols not working inside of compileFinal-ed local functions

Recommended Posts

Hello,

 

I have the following situation:

 

 

TestFile.sqf

#define DefinedText "some text"
//
waitUntil { sleep 1; !isNull player };
//
TestFunc = compileFinal "
	systemChat DefinedText;
";
//
call TestFunc;

 

 

init.sqf

TestFile = compileFinal preprocessFileLineNumbers "TestFile.sqf";
[] spawn TestFile;

 

 

I want to have everything organized in this way if possible - no CfgFunctions, have separate files with distinct functionalities that are initialized/run from 'init.sqf'. I want to use defined symbols (#define) inside of my 'TestFunc' and also use 'compileFinal' to secure it. It does not work:

'
systemChat |#|DefinedText;
'
Error Undefined variable in expression: definedText

It seems that there is no pre-processing done on functions that are 'compileFinal'-ed so #define directives do not work properly. Is there a proper way that I'm missing or a workaround to use both 'compileFinal' and defined symbols in a local function?

 

Thanks in advance for all responses!

Share this post


Link to post
Share on other sites

I already answered you that in Discord 14 hours ago...
Here is a copy paste just for you

 

Quote

use {} then, use str to turn it to string, and cut off the starting { and ending } using select

 

Share this post


Link to post
Share on other sites

Thank you, I'm not sure it would work though and I'm still hoping for a more clean/elegant solution.

Share this post


Link to post
Share on other sites
33 minutes ago, Extremist79 said:

 

 

I want to have everything organized in this way if possible - no CfgFunctions, have separate files with distinct functionalities that are initialized/run from 'init.sqf'. I want to [...] use 'compileFinal' to secure it.

 

 

Why don't you want to use cfgFunctions? Properly defined functions are protected by default against rewriting, unless you force "allowRecompile" or play from the editor.

  • Like 1

Share this post


Link to post
Share on other sites

Doing this for someone not tech savvy so trying to make the script deployment and customization (hence the #defines) as simple and easy as possible.

Share this post


Link to post
Share on other sites
#define DEFINEDTEXT "some text"

testFunc = compileFinal ("
	systemChat '" + DEFINEDTEXT + "';
");

testFunc2 = compileFinal ("
	systemChat " + str DEFINEDTEXT + ";
");

testFunc3 = compileFinal format[ "
	systemChat '%1';
", DEFINEDTEXT ];

You cannot expect the processor to pass characters contained within a string for definitions.

 

I would strongly recommend CfgFunctions. All the end user would have to do is add one line to the CfgFunctions definition inside description.ext. No messing around with them having to compile files.

//description.ext

class CfgFunctions {
	#include "someFolder/myProvidedFunctionsLibrary.hpp"
}

Then behind the scene in your provided package..

//someFolder/myProvidedFunctionsLibrary.hpp

class someProject {
	tag = "TAG";
	class myFunctions {
		file = "someFolder";
		class testFunc {};
	};
};
//someFolder/fn_testFunc.sqf

params[ "_text" ];

systemChat _text;

Then teach your end user how to use arguments. All they would have to know is...

//init.sqf

[ "some text" ] call TAG_fnc_testFunc;

Benefits you both. You have easy clean code to maintain. The end user learns something easy that in the long run will help them to understand other things they may come across. :shrug:

Share this post


Link to post
Share on other sites

That’s a horrible way to define functions as in MP your functions won’t be ready in time for remote execution on JIP and if someone compiledFinal the same variable and it has been broadcast your function won’t compile at all. 

  • Like 2

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

×