Game Development Community

Another setBlendColor issue

by David Helmer · in iTorque 2D · 06/04/2012 (12:07 am) · 6 replies

I'm getting:
start setEnabledColor
t2dSceneObject::setBlendColour() - Invalid Number of parameters!
end setEnabledColor

when the code is:
function BattleButton::setEnabledColor(%this){
	echo("start setEnabledColor");
	if(%this.enabledColor == nil){
		%this.setBlendColor($enabledColor);
	} else {
		//echo(%this SPC "this is weird" SPC %this.enabledColor);
		%this.setBlendColor(%this.enabledColor);
	}
	echo("end setEnabledColor");
}

however it works just fine:
start setEnabledColor
humanSlotButtonhumanSlotButton this is weird .85 .85 .85
end setEnabledColor

when I uncomment that echo
function BattleButton::setEnabledColor(%this){
	echo("start setEnabledColor");
	if(%this.enabledColor == nil){
		%this.setBlendColor($enabledColor);
	} else {
		//echo(%this SPC "this is weird" SPC %this.enabledColor);
		%this.setBlendColor(%this.enabledColor);
	}
	echo("end setEnabledColor");
}

may have to do with the bizarre repetition of %this

all in all I'm confused. I'm happy to have it working, but would prefer to be doing it "correctly".

here's some additional background, slotButton is the class of the object and BattleButton is the SuperClass. Here's where enabledColor gets set:
function slotButton::onLevelLoaded(%this, %scenegraph){
	%this.onBattleButtonLevelLoaded(%scenegraph);
	%this.enabledColor = $lightColor;
	%this.setButtonEnabled(%this.isHuman);
}

thoughts? not putting this as a bug merely because I'm so confused

#1
06/04/2012 (12:43 am)
I'm not sure if you can use 'nil' in TorqueScript. I think you should use 'null' if what you're checking for is undefined. Maybe you can use both, I've always seen 'null' though.
#2
06/04/2012 (4:10 am)
setBlendColor takes four values, 3 color and 1 alpha.
#3
06/04/2012 (5:02 am)
I tried it with all 4 parameters and still had the same results (I thought that was the issue as well).

The documentation says that alpha is an optional parameter that defaults to 1.0.

setBlendColor(float red, float green, float blue,[float alpha=1.0])

tomorrow morning I'll run more tests with all 4 parameters but I don't have my hopes up since this is mainly about the echo fixing things (which is really odd).

I can only guess that this is some reference trickery where it's usage in the echo resolves a reference or something of that sort.

That's only a theory until I break out the debugger in XCode.
#4
06/17/2012 (12:04 am)
Speaking to Conor's point, using == null or == nil caused hard crashes eventually. I've removed them altogether and am just making sure the value is initialized no matter what.
#5
06/17/2012 (5:35 am)
I've only ever used null for wiping a variable, never for comparison.

For example you might use...

$currentSelection = $player1;

then later...

if (isObject($currentSelection)){
// do something to the selection
$currentSelection = null; // to erase the selection
} else {
// $currentSelection was null
// echo an error
}
#6
06/17/2012 (2:25 pm)
great, thanks for the tip