Jump to content
Sign in to follow this  
tj72

Scripting Tips

Recommended Posts

This is a thread for posting scripting tips. These tips could cover anything from time savers, workarounds or any piece of knowledge that might help your fellow scripters save some headaches.

Mine are these:

1) comments: Use hint with format ["%1", _this_var] to find out what your script is using for a particular variable. This is a well known thing but I realized once your script gets big you have alot of hints that might be getting in the way. So I do a hint switch.

? test_hint == 1 : hint  ["%1", _this_var]

In init we have

test_hint = 1

if I switch it to 0 then all the hints are turned off.

You could also do test_hint1-4 if you wanted different sections. This is great if you have multiple scripts running and want to check them at any time.

2) Time variable.

So you have your hints set up from above. Now you need enough time to read the hint before another hint pops up.

Instead of using ~1

you can have ~test_time

In init we have

test_time = 1

then you have a kind of throttle for how long the wait time is for the whole script.

You could also have test_time1-3 if you wanted timing for different sections. You can set timing up for all your different scripts and this is alot quicker than doing ~#'s all down a long script~

3) Reserve 0 in Arrays.

If you want a list of units/vehicles/anything in an array.

All_Trucks = [Truck1,Truck2,Truck3]

Its better to have

[0,Truck1,Truck2,Truck3]

In theory you could have a Truck0  instead but I like the old goose egg since it will break if you are selecting item 0. (Who would name something Zero to start intead of 1?)

This way All_Trucks select 1 equals Truck1 and so forth This  is a better logical format and you will not have to knock one number over when your getting Truck# deep in another script.

Maybe these are basic ones but I really saved alot of time by using them so I thought I would share.

Thats all I can think of for now!

Share this post


Link to post
Share on other sites

New Tip : Use a scripting console! I use Vektorboson's console 2.0. Using one can really speed up your development, as you can monitor or define any global variable you wish in game. You can also execute code in game, which removes all that fiddling around with radio trigger prompted test scripts.

Share this post


Link to post
Share on other sites

Also watch for typos (they are easy to make as my Title shows sad_o.gif )

Run edit/Find to check all your typos it saves alotta time.

Make Var names short and descriptive Transport_Group can be Trnspt_Grp you can still tell what it is without the vowels

Make your global variables custom named

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

EnemyDead = 0

should be

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

TJ_EnmyDd = 0

Here I shortened the name and made it more custom to avoid conflicts with any other scripts I might add in from other people.

 Make lots of error conditions

if you run a bunch of checks with conditions that should go to another part of the script (like a "Goto" or similar) put an error function at the bottom

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

? EnmyDd == 0: _Fnctn = "Attack"

? EnmyDd == 1: _Fnctn = "Defend"

etc...

at the end of this put:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

hint "Error could not define function type!"

because you wanted the script to never hit this hint you know you are not giving the proper variable/array to the script and you can check from there.

once you have several cases of this in place and your script breaks you will be able to sort out the source of the problem much quicker.

Share this post


Link to post
Share on other sites
Guest

Vehicle stuff ive discovered the last (intense) week of scripting:

?!(canFire Tank1):player sidechat "Tank cant fire"

canfire is returning nothing for empty vehicles, it is supposed to return true of false depending on damage value..

Using waypoint 'get out' for vehicles will set allowGetIn value to false for those units, therefore, if one tries to get them back in thru scripting, that value must be set to true again. This was a difficult one to find, I was scripting them to get in, then using getout wp command, of course as soon as id set allowGetIn back to true, theyd run back in, as ive also found, until OrderGetIn is set to false for each occupant, theyl always run back in the vehicle if allowGetIn is true - I know, this was alot, but my fix was easy, I just use a 'move' waypoint, {[_x] OrderGetInFalse} forEach (units TankersGroup1), and no problems with allowGetIn anymore...

for finding out if a unit is a vehicle in a trigger list, thanks to UNN: isKindOf works wonders, eliminates need to check on every single 'sub' type of vehicle:

Example:

{if(_x isKindof "Tank") then {_x doMove (getPos player)}} forEach (list temptrigger)

This would take any tank in the trigger list and move it to players position

cant think of anything else off hand right now on that...

Share this post


Link to post
Share on other sites

These forums have helped me alot over the years, so

i can share this:

If you want to write a future addon-compatible script,

then the easiest way is to use the new ArmA config commands.

For example:

You a writing a detection script for a tank commander, that has to

determine whether the spotted enemies are equipped with anti-tank weapons.

As long as there are only the standard weapons in the mission you are fine,

but if people add more and more different launchers to the game, you can't

anticipate their names and put them into a check-array.

So it is recommendable to check the enemies weaponry for any kind of

weapons that inherit the launcher class in their config.

The following sqf checks if a unit called _enemy has a launcher.

Instead of the hints you can of course use the appropriate actions that the tank

commander would take once he detects a launcher-equipped soldier (engage,register,escape...)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_weaparr= weapons _enemy;

_weapclassarr=[];

_i=0;

{_weapclass= inheritsFrom (configFile >> "CfgWeapons" >> _weaparr select _i);_weapclassarr set [_i,_weapclass];_i=_i+1;} foreach _weaparr;

_launcher="";

for [{_j=0}, {_j<count _weapclassarr}, {_j=_j+1}] do

{

if (format ["%1",_weapclassarr select _j]=="BIN\CONFIG.BIN/CFGWEAPONS/LAUNCHER") then

{

_launcher=_weaparr select _j

};

};

if (format ["%1",_launcher]!="") then

{

hint format ["Enemy has a launcher of the type: %1",_launcher]

}

else

{

hint "Enemy has no launcher"

};

This is just an example of the numerous occasions where a config check is the way to go.

Hope that helped.

Charon

Share this post


Link to post
Share on other sites

Thanks guys,

No one else has any others?

Come on guys I know theres more out there! Why not save your bretheren from the seventh circle of scripting hell.

smile_o.gif

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  

×