Jump to content

Recommended Posts

Hey guys,
 
usualy I write a function put it in an example.sqf and then I do this:
 

fnc_example = compileFinal preprocessFile "example.sqf";

 
now I have a file with a bunch of functions in the file example_fncs.sqf like this:
 

fnc_example_a =
{
};

fnc_example_b =
{
};

fnc_example_c =
{
};

how can I preprocess the file and precompile that functions for the later use with call and spawn?

Share this post


Link to post
Share on other sites

I knew that this should be easy but I didnt get howto do it. thx alot guys...

Share this post


Link to post
Share on other sites

I have to agree with setting up your own function library.  We are 2016 now, the CfgFunction is the new way to go.

 

for example

class MyFunctions{
	tag = "MYFNC";

	class MyFunctionsInitialize {
		file = "functions";

		class getUnitCount {};
	};
};

Then put your functions in seperate sqf files in the folder functions with fn_ in front of them fe: fn_getUnitCount.sqf

 

You can then call them 

 

_count = [] call MYFNC_fnc_getUnitCount;

 

experiment with it you will not regret it !

  • Like 2

Share this post


Link to post
Share on other sites

if you just call the execVM on the file where your functions are the file will be preprocessed. You dont need to do anything else. The result as far as I know should be same in both methods when calling those function.

  • Like 1

Share this post


Link to post
Share on other sites

Why not set up your own functions library?

 

Cheers

hmm ... idk. could u explain that a bit more pls?

I have to agree with setting up your own function library.  We are 2016 now, the CfgFunction is the new way to go.

 

for example

class MyFunctions{
	tag = "MYFNC";

	class MyFunctionsInitialize {
		file = "functions";

		class getUnitCount {};
	};
};
Then put your functions in seperate sqf files in the folder functions with fn_ in front of them fe: fn_getUnitCount.sqf

 

You can then call them 

 

_count = [] call MYFNC_fnc_getUnitCount;

 

experiment with it you will not regret it !

I ll try that.

thx alot

Edited by sarogahtyp
  • Like 1

Share this post


Link to post
Share on other sites

okay, I read that wiki entry about the function library and yes of course i ll use it. maybe i didnt get all of that wiki entry because some questions remain.

If I understood that correct then I ve to write every function in its own sqf file if I use that library or is it possible to do one file with a few functions with it?

Next question. Is there a way to force server sided functions to be compiled at server only?

Share this post


Link to post
Share on other sites

The point of the library is to have, one function, one file, in theory, sure you could put more than one function per file and precompile/postInit them, but it takes away from the intent of the library (at least in my opionion).

For server side stuff, you could either make a server side addon, or just make sure at the top of your server functions to have a check, if the accessing machine isn't the server, exit the function.

  • Like 1

Share this post


Link to post
Share on other sites

The point of the library is to have, one function, one file, in theory, sure you could put more than one function per file and precompile/postInit them, but it takes away from the intent of the library (at least in my opionion).

For server side stuff, you could either make a server side addon, or just make sure at the top of your server functions to have a check, if the accessing machine isn't the server, exit the function.

thx for that info.

seems to be the time to learn how to create addons...

Share this post


Link to post
Share on other sites

thx for that info.

seems to be the time to learn how to create addons...

Easier than you may think, you basically just add a config.cpp file (essentially similar to the description.ext) declare your functions there (in addition to CfgPatches) and then all the other necessary function files, use A3 Tools to pack it, done :).
  • Like 1

Share this post


Link to post
Share on other sites

Take a look at

 

https://github.com/Celludriel/dyncap

 

It's a small lib I created a while back and updated  a few days ago.  There is a perfect example on using CfgFunctions.  You really don't want one file with a bunch of functions, each function is just it's own file.  A lot has to do with code cleanliness

Share this post


Link to post
Share on other sites

Okay, as I said I ll use that libráry in future but I ve some thoughts I d like to throw.

that library has surly advantages but I see some disadvantages.

If I d like to release a script then I want to release it as easy as possible for the mission designer who will use it. I dont like that the functions must be defined in description.ext. A mission designer who wants to use the functions has to merge my description.ext with its own. As some guys r only modifying existing missions to implement some more features and then run it on their server they dont have much knowledge about description.ext.

They just want to have a command to init the script and then use the features of it via functions. The necessity of those description.ext entry forces me as the creator of a script to provide two ways for implementation of my scripts in missions now.

The easy way with the classic initing and precompiling and for the mission designers who r familiar with description.ext the way with that function library.

 

It would be easier if there were a way to implement the functions in the library by just including a custom file in discription.ext by doing somethinge like #include "custom.ext"...

Share this post


Link to post
Share on other sites

You can do that, I have this in my description.ext for example:

class CfgFunctions {
	#include "SideOps\CfgFunctions.hpp"
};

And the CfgFunctions.hpp:

class FRED {
	tag = "FRED";
	class sideOps {
		file = "SideOps\Functions";
		class endSideGraphic {};
		class infoText {};
		class selectMission {};
		class squadPatrol {};
		class strategicMapOpen {};
		class taskPatrol {};
		class teamPatrol {};
		class typeText {};
		class vehiclePatrol {};
	};
	class missionTypes {
		file = "SideOps\MissionTypes";
		class Case0Rescue {};
		class Case1Steal {};
		class Case2Target {};
		class Case3Destroy {};
		class Case4Pilot {};
		class Case5Sabotage {};
		class Case6Transport {};
		class Case7Convoy {};
	};
};

Works perfectly and it even shows up in the ingame functions viewer.

  • Like 2

Share this post


Link to post
Share on other sites

okay that is a good thing, but not perfect. the mission designer has to implement it at the correct position. it would be better if he could just write the include at top of description.ext.

but thanks for ur hint that its generally possible to do so.

Share this post


Link to post
Share on other sites

Not to be a complete ass, but honestly most decent mission makers can probably figure out what to do with it given a proper example as many scripters have given for their code (look at all my code pages), it's not complete rocket science, and if a mission maker truely wants the feature you provide I'm sure they will take the time to find out how to implement it.

  • Like 3

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

×