Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Log In with Steam Sign In
  • Create Account
Welcome to AUSARMA - The Dedicated Australian & New Zealand Arma Community
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and much more. If you already have an account, login here - otherwise create an account for free today!

Learning to use CBA in your missions

- - - - -

7 replies to this topic

Poll: I find this topic useful... (5 member(s) have cast votes)

I find this topic useful...

  1. Yes (5 votes [100.00%])

    Percentage of vote: 100.00%

  2. Neutral (0 votes [0.00%])

    Percentage of vote: 0.00%

  3. No (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1
wolffy_au

    MSO Developer

  • Member
  • 609 posts
  • country
Well it might be a surprise to some, but I've never really learnt to use CBA functionality in my coding.

I use the odd function but never got into use the shortcut macros, etc. Recently, Sickboy enabling Function Caching, which provides significant performance improvements to large projects - like MSO. So I've finally pulled my finger out and started to look at using it.

In doing so, I will try to document what I learn here, for all to learn from.

Posted Image


#2
wolffy_au

    MSO Developer

  • Member
  • 609 posts
  • country
Ok, first thing to learn is this function caching stuff.

So normally, you "create" a function using something like this:
fn_Client_SyncHQState = compile preprocessFileLineNumbers  "support\modules\WHB_FOBspawn\common\fn_Client_SyncHQState.sqf";

There is a preferred method of creating functions using the BIS Functions module (see here - http://community.bis...g_new_functions). These are automatically cached by CBA, which covers most of my functions anyway.

But for the odd function like the above, here is the replacement code:
#include "\x\cba\addons\main\script_macros_mission.hpp"
 
fn_Client_SyncHQState = COMPILE_FILE2(support\modules\WHB_FOBspawn\common\fn_Client_SyncHQState.sqf);

This would utilise the CBA Function Caching and optimise performance.

Posted Image


#3
wolffy_au

    MSO Developer

  • Member
  • 609 posts
  • country
Next most useful CBA Macro would have to be PARAMS.

Normally, you would do something like this:
private ["_target", "_specs"];
_target = _this select 0;
_specs = _this select 1;

With CBA, you can shorten it to this:
#include "\x\cba\addons\main\script_macros_mission.hpp"
 
PARAMS_2(_target,_specs);

Also PARAMS_1 supports both: [_firstParam] and _firstParam call function, so you dont HAVE to use an array as parameter for PARAMS_1.

See here for more info - http://dev-heaven.ne...p.html#PARAMS_n

If _specs was optional (and the default value being an empty string (""), you could do the following:
#include "\x\cba\addons\main\script_macros_mission.hpp"
 
PARAMS_1(_target);
DEFAULT_PARAM(1,_specs,"");

See here for more info - http://dev-heaven.ne...l#DEFAULT_PARAM

Note: Make sure there are no spaces between parameters.

Posted Image


#4
kju

    Senior Member

  • Member
  • 212 posts
  • country
A word of advice here on macros:

Many very experienced and intelligent coders say code readability is among if not the most important goal.

Macros often and easily make code a lot harder to understand.
For example without knowledge about the macro, you have to assume from the name, which is often badly chosen, what it might do.

What is the real way to go:
1. Don't be lazy. To save a few keyboard pushes isn't worth it.
2. Make use of and support IDEs that provide code completion and code templates.

#5
wolffy_au

    MSO Developer

  • Member
  • 609 posts
  • country
kju, can you link us to these IDEs you're referring too?

I disagree with your statement though - once you know what the macro is for, its a lot less effort to use and read it. Yes I agree, its difficult for someone who has never used those particular macros before which is why I have taken this long to start using them, but if I had a cheat sheet like this thread - I would have adopted them a lot sooner.

Posted Image


#6
-ZSU- Gnarly

    Senior Member

  • Member
  • 191 posts
  • country
Good thread Wolffy, interesting to see what you come up with!



I recently got reminded using a trigger condition such as:

Quote

player distance briefcase <=2

and an On Act such as:

Quote

titleText [""A female civilian has been found."",""PLAIN DOWN""];

the text will only be returned to the player activating the trigger, not all players.


Aside from using a hint (which I think is global), someone somewhere in a thread about MP messages suggested that CBA had some built in function to handle MP messages better? have you uncovered anything in your travels on this?

Edit: whilst writing this, dug up this, but must admit, not really sure what I need to do to make the above TitleText global from within a trigger:

http://dev-heaven.ne...m_Events_System
Check out my ARMA2 videos at http://www.youtube.c...gnarlyification

Posted Image

#7
kju

    Senior Member

  • Member
  • 212 posts
  • country
skufer and sqfeditor are the two most recent

How is it less effort to read? To save typing, the macros are giving awkward, cut names.
In addition they hide what is being done. Normally you use functions to be able to step through code
from bottom to the top.

Quote

its difficult for someone who has never used those particular macros before

One perfect example of a key issue.

I am curious wolffy - do you code for a living and if so did you study software engineer and read books of experienced people?

#8
wolffy_au

    MSO Developer

  • Member
  • 609 posts
  • country

View Post-ZSU- Gnarly, on 02 October 2011 - 02:20 PM, said:

Aside from using a hint (which I think is global), someone somewhere in a thread about MP messages suggested that CBA had some built in function to handle MP messages better? have you uncovered anything in your travels on this?
Yeah, that link is the way to go. CBA_fnc_globalEvent is the way to go.


kju, I'm not going to debate the pros and cons fo MACROs with you - you have your opinion and a herd of wild horses won't sway you from it.

Not sure what you're trying to achieve asking me about my experiences with software engineering - no matter how I answer that question, it can only end in further argument.

Your points have been raised and acknowledged, now let me get back to displaying examples.

Posted Image