Modifying a Global
Moderators: Slitherine Core, BA Moderators
Modifying a Global
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);
}
}
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

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Modifying a Global
Yes - that is exactly how it is intended to work.
Cheers
Pip
Cheers
Pip
-
Old_Warrior
- Major - Jagdpanther

- Posts: 1022
- Joined: Fri Apr 30, 2010 3:13 am
Re: Modifying a Global
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

- Posts: 3151
- Joined: Fri Apr 06, 2012 6:18 pm
- Location: Palau
Re: Modifying a Global
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
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

- Posts: 3151
- Joined: Fri Apr 06, 2012 6:18 pm
- Location: Palau
Re: Modifying a Global
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
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
Re: Modifying a Global
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.
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

- Posts: 1022
- Joined: Fri Apr 30, 2010 3:13 am
Re: Modifying a Global
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!
But thanks for an explanation of the term - can you give some examples of items in the game that use a global variable?
But thanks for an explanation of the term - can you give some examples of items in the game that use a global variable?
Re: Modifying a Global
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

- Posts: 1022
- Joined: Fri Apr 30, 2010 3:13 am
Re: Modifying a Global
Got it. Working with them now.
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Modifying a Global
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
Cheers
Pip

