Page 1 of 1

Modifying a Global

Posted: Mon Jul 30, 2012 6:19 pm
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);
}
}

Re: Modifying a Global

Posted: Mon Jul 30, 2012 7:04 pm
by pipfromslitherine
Yes - that is exactly how it is intended to work.

Cheers

Pip

Re: Modifying a Global

Posted: Wed Aug 01, 2012 3:46 am
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)

Re: Modifying a Global

Posted: Wed Aug 01, 2012 8:58 am
by GottaLove88s
Starting with "what is a global" please?

Re: Modifying a Global

Posted: Wed Aug 01, 2012 8:59 am
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?

Re: Modifying a Global

Posted: Wed Aug 01, 2012 10:14 am
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.

Re: Modifying a Global

Posted: Wed Aug 01, 2012 1:34 pm
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?

Re: Modifying a Global

Posted: Wed Aug 01, 2012 2:36 pm
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.

Re: Modifying a Global

Posted: Wed Aug 01, 2012 2:39 pm
by Old_Warrior
Got it. Working with them now.

Re: Modifying a Global

Posted: Wed Aug 01, 2012 2:46 pm
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