Page 1 of 1

Check returning value

Posted: Wed Aug 13, 2014 8:46 pm
by enric
The action script for units, CHECK_UNIT_ACTION, is supposed it return a value.
To catch this value I believed a must use:

int ret;
ret = CHECK_UNIT_RESUPPLY(me, unit, tilex, tiley);

But I'm getting not the expected value:

FUNCTION UISETUP_UNIT_ACTION(me, tilex, tiley)
{
int unit;
int ret;

ret = CHECK_UNIT_RESUPPLY(me, unit, tilex, tiley);
StartString() ;

if(ret<0)
{
PrintString("IDS_TT_CANNOTRESUPPLY") ;
}
else
{
PrintString("IDS_TT_RESUPPLY") ;
}
}

I put Log just at the end of the CHECK_UNIT_ACTION:

Log ("returned", ret);
Return ret;

And I see in the log window two values: -1, 8, so which one is catching the UISETUP_UNIT_ACTION?

Re: Check returning value

Posted: Wed Aug 13, 2014 9:34 pm
by pipfromslitherine
The Check function is probably also being called by other code elements (e.g. to flag actionable units, or work out what orders can be shown). Is that what you are asking?

Cheers

Pip

Re: Check returning value

Posted: Thu Aug 14, 2014 7:14 am
by enric
I'm testing in SP, so nothing is happening, just my mouse actions.

I send you the complete function, just before the "return" there is a Log.

In the image, with the truck selected and the cursor over himself, you get: -2, -2.
In the other image just moving the cursor over another unit you get: -1, 8; -1,8...

FUNCTION CHECK_UNIT_RESUPPLY(me, unit, tilex, tiley)
{
int ret ;
int resupplyCost;

resupplyCost = 8;
ret = -2;

// Only truck resupply
if ( (IsUnitType(me, "british_resupply_truck")==1) || (IsUnitType(me, "US_resupply_truck")==1) || (IsUnitType(me, "german_resupply_truck")==1) )
{
// Only adjacent, not deploying
if( (GetDistanceBetweenTiles(tilex, tiley, GetUnitX(me), GetUnitY(me)) == 1) && (IsDeploying() != 1 ) )
{
if ( ( GetUnitSide (me) == GetUnitSide(unit) ) && ( GetAttrib (me, "morale") > 49) && ( GetAttrib (unit, "morale") > 49))
{
ret = -1 ;
// AP needed to ResupplyUnit
if ( ( GetAttrib (me, "AP") >= 8 ) && ( GetAttrib (unit, "AP") >= 8 ) )
{

//AP charges
if ( GetAttrib(unit, "APCharges") != GetBaseAttrib(unit, "APCharges") )
{

ret = resupplyCost
}

// smoke
if (GetAttrib(unit,"eng_smoke") == 1)
{
if ( (IsUnitSquadType(unit, "infantry")==1) && ( GetAttrib(unit, "smoke_shots") < 6) )
{
ret = resupplyCost
}
if ( (IsUnitSquadType(unit, "tracked")==1) && ( GetAttrib(unit, "smoke_shots") < 2) )
{
ret = resupplyCost;
}
}
}
}
}
}
Log ("check final ret value", ret);
return ret ;
}
itself.jpg
itself.jpg (62.74 KiB) Viewed 9386 times
Capable.jpg
Capable.jpg (74.29 KiB) Viewed 9386 times

Re: Check returning value

Posted: Thu Aug 14, 2014 7:56 am
by Amaris
enric wrote:

Code: Select all


FUNCTION UISETUP_UNIT_ACTION(me, tilex, tiley)
{
 	int unit;
	int ret;
	
	ret = CHECK_UNIT_RESUPPLY(me, unit, tilex, tiley);
	StartString() ;
	
	if(ret<0)
	{
		PrintString("IDS_TT_CANNOTRESUPPLY") ;
	}
	else
	{
		PrintString("IDS_TT_RESUPPLY") ;
	}
}
Not sure if this is the problem but I saw an error on this code: when you call the CHECK function, the variable unit is declared but there is no instruction to give it a value.

Re: Check returning value

Posted: Thu Aug 14, 2014 8:23 am
by enric
Amaris wrote:
enric wrote:

Code: Select all


FUNCTION UISETUP_UNIT_ACTION(me, tilex, tiley)
{
 	int unit;
	int ret;
	
	ret = CHECK_UNIT_RESUPPLY(me, unit, tilex, tiley);
	StartString() ;
	
	if(ret<0)
	{
		PrintString("IDS_TT_CANNOTRESUPPLY") ;
	}
	else
	{
		PrintString("IDS_TT_RESUPPLY") ;
	}
}
Not sure if this is the problem but I saw an error on this code: when you call the CHECK function, the variable unit is declared but there is no instruction to give it a value.
Thanks, but the "problem" is understanding why the CHECK functions return two values as you may seen in the images.

Re: Check returning value

Posted: Thu Aug 14, 2014 8:31 am
by Amaris
Probably because the CHECK function is called twice. :mrgreen: So why ?

Can you log the ID of unit also?

Re: Check returning value

Posted: Thu Aug 14, 2014 9:38 am
by enric
Adding the id's (me, and unit) to the end:

Log ("check final ret value", ret, me, unit);

The first returned values are from "me", and the pointed "unit", for exemple
me = 7
pointed unit= 5

8, 7, 5 and inmediately
-1, 7, 0 (Zero is a unit not involucrated in these actions)

if I try with any other unit I always receive:
8, 8, theid of the other unit, and
-1,7,0

Re: Check returning value

Posted: Thu Aug 14, 2014 3:05 pm
by pipfromslitherine
The CHECK function is called by the code pretty much every tick to see what orders should be shown at the cursor position.

Cheers

Pip

Re: Check returning value

Posted: Thu Aug 14, 2014 6:11 pm
by enric
pipfromslitherine wrote:The CHECK function is called by the code pretty much every tick to see what orders should be shown at the cursor position.

Cheers

Pip
BA scripting is like the universe, fascination but incompressible.
Added at the end of a CHECK function
Log ("check final ret value", ret, me, unit); So, me is the selected unit and unit is the unit where the cursor is pointing.

If the cursor is on me, so me = unit the functions return the same value twice, for example if me = 7
check final ret value 7,7,-2; -2 because the action is not possible on itself.
check final ret value 7,7,-2
when pointing on another unit
check final ret value 7,5,8 and
check final ret value 7,0,-1
5 if the unit id where the cursor is pointing
0 is the id of a unit not involved in the action.

pointing to another unit
check final ret value 7,3,8
check final ret value 7,0,-1

I was just trying to understand, I have different bypass to do the job.

Re: Check returning value

Posted: Thu Aug 14, 2014 7:31 pm
by pipfromslitherine
It's possible that the CHECK function was being used to update the flags on enemy units (E.g., can they be actioned by this currently selected unit). It's definitely complex :)

Cheers

Pip

Re: Check returning value

Posted: Thu Aug 14, 2014 7:38 pm
by enric
pipfromslitherine wrote:It's possible that the CHECK function was being used to update the flags on enemy units (E.g., can they be actioned by this currently selected unit). It's definitely complex :)

Cheers

Pip
"It's definitely complex :)"

Yes, this make it very interesting :) , above all I do it for fun. If I were obliged by job I will complain about the documentation !! :D

Re: Check returning value

Posted: Thu Aug 14, 2014 9:36 pm
by jcb989
enric wrote:BA scripting is like the universe, fascination but incompressible..
:D

Re: Check returning value

Posted: Fri Aug 15, 2014 3:59 pm
by pipfromslitherine
One of the problems (kinda!) in something like BA where we really let you do everything that the dev team does is that, if you really want to get right down in to it, you almost need to be part of the team. Documenting every interaction would produce far more documentation than anyone would read (or indeed anyone could write) and almost certainly STILL not answer the questions that people actually want to know the answers to :).

Honestly I think that we have probably added too much to BA in terms of features and modding stuff. It does allow for some very cool things, like your mods or complete mods like the naval one, but the sheer number of possible things people can create increases the complexity.

Oh well, I guess it is a good problem to have in some ways! But at least you'll always have me.... ;)

Cheers

Pip

Re: Check returning value

Posted: Fri Aug 15, 2014 8:51 pm
by jcb989
pipfromslitherine wrote:Honestly I think that we have probably added too much to BA in terms of features and modding stuff.
Heresy, lol
pipfromslitherine wrote: But at least you'll always have me.... ;)
Hope so!