Jump to content
Sign in to follow this  
thdman1511

When to use include command in Scripts

Recommended Posts

As I continue to learn scripting, I am just wondering whether there are guideline on when to use #include in a script. I have seen it used widely in init.sqf files, and would like to know, if there are any general guidelines on it use in scripting and when should a file be included in the init.sqf or config file.

Share this post


Link to post
Share on other sites

You never need to use it. But it helps if you want to keep things clean or to separate a lot of your code from other's code. There's probably some code optimizational reason for it too but 99.9% of what you'll be writing probably doesn't need it. heh

Share this post


Link to post
Share on other sites

if I am not wrong the effect of include is nothing else than copy all content of another file into the file where the include is. Nothing more and nothing less. I would recommend you to deny its usage if it is not needed. Some nice spots to use it would be in classes:

class A

{

#include otheronesclass

class yourclass

{

};

};

without the include you have to copypaste the other class into your description.ext (in addons you also can use another config.cpp...)

Share this post


Link to post
Share on other sites

It's useful if you use one or several macros defined as local variables

Share this post


Link to post
Share on other sites

speaking of macros - is there a tutorial or reference on how to use macros in ArmA - seen em used but a lot (especially domination) and never really fully understood their purpose or the reason to use em over other methods.

Share this post


Link to post
Share on other sites

I dont know anything about macros but in C they also work like copypaste. That means if you would use a function at a point the function has to be called (needs time). often calling small functions (only a few lines) reduces speed! But macros increases the binary size and can fuck your program. No joke!

I think macros in arma will work similar...

Share this post


Link to post
Share on other sites

http://community.bistudio.com/wiki/PreProcessor_Commands

Using domi as an example;

macros.sqf

#define __cppfln(xdfunc,xfile2) xdfunc = call compile preprocessFileLineNumbers #xfile2

The macro is now set up so we only need to write __ccppfln(function_name,path_to_script).

#xfile2 means that the path will be converted into a string

#include "macros.sqf"
// contents of macros.sqf now exists in this script
__ccppfln(TAG_check_Score,scripts/functions/checkscore.sqf)
// TAG_check_score is now compiled
_value = [player] call TAG_check_score

It allows you to keep commonly used commands in one file, allowing it to be easily edited etc. It's just another way of doing stuff :) Use whatever you prefer.

  • Like 1

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  

×