local variables declared in the middle of a bos function

local variables declared in the middle of a bos function

Discuss your problems with the latest release of the engine here. Problems with games, maps or other utilities belong in their respective forums.

Moderator: Moderators

Post Reply
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

local variables declared in the middle of a bos function

Post by zwzsg »

In the unit scripts (cob/bos), functions can use local variables.

For exemple in the ARMTSHIP.bos from OTA, there is:

Code: Select all

BoomCalc(posxz,posy)
	{
	var dxz,dy,lenxz;
	....
	}
When that var ... line is in the middle a big function, TA accepts it but not Spring.

Because TA can't handle it when too many variables are declared, I like to declare my local variables only when they are needed, instead of always declaring everything at the beginning of the function.

But that makes scripts that work fine in TA3.1c to fail in Spring70b2!





Here's the unit that led me to believe that:
ArmDuck_Spring_Local_Var_Declaration_Buggy.ufo

Its script goes basically like:

Code: Select all

TransportDrop(id,xz)
	{
	if(manual_unload)
		{
		some simple code;
		return;
		}

	//Auto unload
	var shape;
	shape=0;
	if(shape==0)
		{
		move the white ball;
		}

	unload the unit on the white ball;
	}
When the variable "shape" is declared like that in the middle of the function, TA handles it fine, but Spring instead fails in the shape=0;if(shape==0) part, which can be seen ingame by the white ball not moving when you unload units.

However, when I move the variable declaration to the top of the function, then it works fine in Spring. The script is a bit long, so search for the text BugBugBug1 and BugBugBug2 to go to the relevant places.
Post Reply

Return to “Help & Bugs”