Page 1 of 1

Init Functions

Posted: Mon Sep 17, 2012 4:29 pm
by enric
When I've some free time I'm continuing trying to understand BA scripting :), so I'll make several questions.

"Any function which is named with INIT_ as the first 5 characters will be called on unit creation."

When is a unit created?

Re: Init Functions

Posted: Mon Sep 17, 2012 5:56 pm
by pipfromslitherine
Units are created in various places. All the placed units on the map are created at map load time (after the force selection screen if memory serves). Also, when new units are created by a script.

You should use the INIT function to AddAttrib any custom attribs that you want to use on the unit.

Cheers

Pip

Re: Init Functions

Posted: Mon Sep 17, 2012 6:38 pm
by enric
i.e if I want to add an attribute to a engineer unit I just put on the scenario.BSF

FUNCTION INIT_us_engineer
{
AddAttrib("Wire"); //this will create this attribute for all engineer in the board?, with value 0?

// how to put a generic value to all engineers?, as SetAttrib(id, string, value) needs to specify a unit (id)?
}

Re: Init Functions

Posted: Mon Sep 17, 2012 9:28 pm
by pipfromslitherine
The INIT_ function needs to be part of the unit script (e.g. in the main game the $DEFAULT.BSF file includes the INIT.BSF file containing the INIT_ function for all the units).

Cheers

Pip

Re: Init Functions

Posted: Tue Sep 18, 2012 6:27 am
by enric
Sorry again, just to be sure, are you telling me that my specific function should be placed in the INI.BSF file?

// setup data to track last target for accuracy purposes
function INIT_UnitData(me)
{
}
then my function
function INIT_myInitFunction(me)
{
}

Re: Init Functions

Posted: Tue Sep 18, 2012 3:55 pm
by pipfromslitherine
The function(s) can be anywhere in any of the script files you include for a given unit. E.g. for the main game, almost all the units just use the $DEFAULT.BSF script file, which includes all the move, fire, etc scripts. Any function which begins with INIT_ will be called at the initialisation stage.

Cheers

Pip