Modifying a Global

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

Modifying a Global

Post by enric »

Should this work? or I have a bad understanding of Set-GetGlobal (that is not defined in any place).

Defined in prebattle setup
SetGlobal ("gVariable",3);

-----
in FUNCTION StartTurn(side):

if ( GetTurn() >= 0 )
{
i = GetGlobal("gVariable");
if (i>0)
{
SetGlobal ("gVariable", i-1);
}
}
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Modifying a Global

Post by pipfromslitherine »

Yes - that is exactly how it is intended to work.

Cheers

Pip
Old_Warrior
Major - Jagdpanther
Major - Jagdpanther
Posts: 1022
Joined: Fri Apr 30, 2010 3:13 am

Re: Modifying a Global

Post by Old_Warrior »

For some of us still learning how all of this works what exactly does this do in laymen's terms (please - no programmer jargon - its the only way some of us will learn this system - I took Basic in college and decided that advance programming was out of my league - but this stuff is not - I just need to understand the terms better)
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Modifying a Global

Post by GottaLove88s »

Starting with "what is a global" please?
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Modifying a Global

Post by GottaLove88s »

Enric/Pip, OW has an excellent idea to write a Fool's Guide to Wargame/BA Scripting... is there a decent book (or website) around that gives a kind of Intro101 to get him and the rest of us started? Where to start? What is BA scripting based on?
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Modifying a Global

Post by rf900 »

For the original question "what is a global" you have to start with what is a variable, a function and scope. Considering you know what is a function and a variable the idea is that each variable "lives" (has a value and you can reference it) inside a function. Global variables instead can be set and retrieved from any function.

In this case they are talking about global variables to a scenario, so basically elements you want to keep track at a scenario level.

BA allows also variables at the campaign level, in case you want to track values along a campaign, setting and retrieving the values any time you want.

I am in favor on doing a more deep guide for BA scripting, but programming knowledge indeed helps. The official guide http://www.slitherine.com/modding/bbc_ba_pc is essential for starting (I am referring mainly to the STUB_Engine PDF) and for the gaps the forum support is very good, also learning with existing examples is the best route IMO.
Old_Warrior
Major - Jagdpanther
Major - Jagdpanther
Posts: 1022
Joined: Fri Apr 30, 2010 3:13 am

Re: Modifying a Global

Post by Old_Warrior »

The guide I am working on will lay out the basic files you need, the basic structuring of them and then build on that and show intermediate and complex examples. Complete with pictures and arrows! :D

But thanks for an explanation of the term - can you give some examples of items in the game that use a global variable?
rf900
Staff Sergeant - Kavallerie
Staff Sergeant - Kavallerie
Posts: 339
Joined: Fri May 04, 2012 6:59 am

Re: Modifying a Global

Post by rf900 »

Usually global variables are needed when you want to keep track of something during the scenario, for example number of victory points held by player or enemy, the status of each vp, mainly for things you want to verify each turn or at any point in the script.
Old_Warrior
Major - Jagdpanther
Major - Jagdpanther
Posts: 1022
Joined: Fri Apr 30, 2010 3:13 am

Re: Modifying a Global

Post by Old_Warrior »

Got it. Working with them now.
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: Modifying a Global

Post by pipfromslitherine »

You use global variables for anything you want to maintain outside of a given function. That is, the variables you define inside a function (using int) exist only when the function is running. Each time it gets called, they are reset to zero. Global variables are maintained for the entire lifetime of a given script (so the mission script has its own set of global variables, and a unit script has its own, etc).

Cheers

Pip
Post Reply

Return to “Battle Academy : Modders Corner ”