Page 2 of 2

Posted: Mon Dec 13, 2010 4:36 pm
by Amaris
The function GetUnitLonely(unit) is being called to run in the function MoraleCheck(), MoraleCheck() even called in the function StartTurn(side).

I do that for optimisation : my function MoraleCheck() use a single loop to go through the player's units, or is an officer and call the function OfficerBonus(unit), or I look if the unit is isolated (with function GetUnitLonely(unit)) and call the function AjustMoral(unit).

Posted: Mon Dec 13, 2010 5:20 pm
by Merr
Amaris wrote:The function GetUnitLonely(unit) is being called to run in the function MoraleCheck(), MoraleCheck() even called in the function StartTurn(side).

I do that for optimisation : my function MoraleCheck() use a single loop to go through the player's units, or is an officer and call the function OfficerBonus(unit), or I look if the unit is isolated (with function GetUnitLonely(unit)) and call the function AjustMoral(unit).

hmm ... I'm sorry I haven't ran the scenario to check this ... I can see the check(for lonelyunit) in the MoraleCheck() ....

Code: Select all

		else
		{
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
		}
But, I'm not seeing anywhere that actually calls the function (to return a value of 0 or 1) ... Shouldn't it read like this ;

Code: Select all

		else
		{
			GetUnitLonely(unit) ;
			
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
		}

Posted: Mon Dec 13, 2010 5:26 pm
by junk2drive
I have played it and as I recall at the beginning of your turn it pops up text that your unit is isolated or bonus. It appears to work to me.

Posted: Mon Dec 13, 2010 5:41 pm
by Merr
junk2drive wrote:I have played it and as I recall at the beginning of your turn it pops up text that your unit is isolated or bonus. It appears to work to me.
I'm just puzzled on how the logic works ... :?

Posted: Mon Dec 13, 2010 7:05 pm
by Amaris
Well I'll try to explain :

Indeed the function GetUnitLonely(unit) return a value of 0 or 1 when it called.

The Syntax of if is :

Code: Select all

if(conditional)
{
  //code
}
else
{
  //code
}
The call of GetUnitLonely(unit) :

Code: Select all

...
			if(GetUnitLonely(unit) == 1)
			{
				AjustMoral(unit);
			}
...
The (conditional) of if is : GetUnitLonely(unit) == 1. So the program call the function GetUnitLonely(unit), return 0 or 1 as follows and finally the (conditional) is 0 == 1 or 1 == 1 as follows.

Posted: Mon Dec 13, 2010 8:00 pm
by Merr
I didn't know that the conditional automatically called the function ... I always thought it(function) had to be called first, then checks against the conditional ... :oops:

Thanks for explaining! I'm just a noob you know :wink: