Init Functions

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

Init Functions

Post 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?
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Init Functions

Post 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
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

Re: Init Functions

Post 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)?
}
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Init Functions

Post 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
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

Re: Init Functions

Post 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)
{
}
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Init Functions

Post 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
Post Reply

Return to “Battle Academy : Modders Corner ”