Check returning value

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: 1854
Joined: Sun May 15, 2011 8:47 am

Check returning value

Post by enric » Wed Aug 13, 2014 8:46 pm

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?

pipfromslitherine
Site Admin
Site Admin
Posts: 8951
Joined: Wed Mar 23, 2005 10:35 pm

Re: Check returning value

Post by pipfromslitherine » Wed Aug 13, 2014 9:34 pm

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
follow me on Twitter here

enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1854
Joined: Sun May 15, 2011 8:47 am

Re: Check returning value

Post by enric » Thu Aug 14, 2014 7:14 am

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 6271 times
Capable.jpg
Capable.jpg (74.29 KiB) Viewed 6271 times

Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Re: Check returning value

Post by Amaris » Thu Aug 14, 2014 7:56 am

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.
“Take care, my friend; watch your six, and do one more roll… just for me.”

enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1854
Joined: Sun May 15, 2011 8:47 am

Re: Check returning value

Post by enric » Thu Aug 14, 2014 8:23 am

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.

Amaris
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 929
Joined: Fri Jul 23, 2010 11:08 am
Location: France
Contact:

Re: Check returning value

Post by Amaris » Thu Aug 14, 2014 8:31 am

Probably because the CHECK function is called twice. :mrgreen: So why ?

Can you log the ID of unit also?
“Take care, my friend; watch your six, and do one more roll… just for me.”

enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1854
Joined: Sun May 15, 2011 8:47 am

Re: Check returning value

Post by enric » Thu Aug 14, 2014 9:38 am

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

pipfromslitherine
Site Admin
Site Admin
Posts: 8951
Joined: Wed Mar 23, 2005 10:35 pm

Re: Check returning value

Post by pipfromslitherine » Thu Aug 14, 2014 3:05 pm

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
follow me on Twitter here

enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1854
Joined: Sun May 15, 2011 8:47 am

Re: Check returning value

Post by enric » Thu Aug 14, 2014 6:11 pm

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.

pipfromslitherine
Site Admin
Site Admin
Posts: 8951
Joined: Wed Mar 23, 2005 10:35 pm

Re: Check returning value

Post by pipfromslitherine » Thu Aug 14, 2014 7:31 pm

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
follow me on Twitter here

enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1854
Joined: Sun May 15, 2011 8:47 am

Re: Check returning value

Post by enric » Thu Aug 14, 2014 7:38 pm

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

jcb989
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1418
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Re: Check returning value

Post by jcb989 » Thu Aug 14, 2014 9:36 pm

enric wrote:BA scripting is like the universe, fascination but incompressible..
:D

pipfromslitherine
Site Admin
Site Admin
Posts: 8951
Joined: Wed Mar 23, 2005 10:35 pm

Re: Check returning value

Post by pipfromslitherine » Fri Aug 15, 2014 3:59 pm

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
follow me on Twitter here

jcb989
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1418
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Re: Check returning value

Post by jcb989 » Fri Aug 15, 2014 8:51 pm

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!

Post Reply

Return to “Battle Academy : Modders Corner ”