cant get return values from other behaviors
by miguel janer · in Technical Issues · 08/17/2010 (10:12 am) · 6 replies
hi, I have troubles withs return statment, i can only use it in the same behaivor, if i vall it from another one it doesnt return nothing.
then if i call it on my ammoitem behavior
any idea what im doing wrong? or return doest works on other behaviors?
function playerAttackBehavior::getAmmo(%this,%tipo)
{
return (%this.ammo[%tipo,1]);
}then if i call it on my ammoitem behavior
function ammoItemBehavior::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contact)
{
if (%dstObj.class $= "player")
{
echo("found ammo");
echo(%dstObj.getAmmo(%srcObj.tipo)); ////all this doesnt works
echo(%dstObj.getMaxAmmo(%srcObj.tipo));
if((%dstObj.getAmmo(%srcObj.tipo)) < (%dstObj.getMaxAmmo(%srcObj.tipo)))
{
%dstObj.setAmmo(%srcObj.tipo, %srcObj.ammo);
}
}
}any idea what im doing wrong? or return doest works on other behaviors?
#2
but now i have discovered another problem, I can use %srcObj.tipo everywhere but not as a parameter example:
thx again!
08/18/2010 (7:35 am)
thanx a lot! I didnt know about that command.but now i have discovered another problem, I can use %srcObj.tipo everywhere but not as a parameter example:
if (!isObject(ammoItemBehavior))
{
%template = new BehaviorTemplate(ammoItemBehavior);
%template.friendlyName = "items de municion";
%template.behaviorType = "Item";
%template.description = "añaden municion de un tipo definido.";
%template.addBehaviorField(tipo, "type of ammo", float, 0);
%template.addBehaviorField(ammo, "number of ammo", float, 0);
}
function ammoItemBehavior::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contact)
{
if (%dstObj.class $= "player")
{
echo("encontrada municion");
echo(%srcObj.tipo); //this works
echo(%srcObj.ammo); //this works
echo(%dstObj.getBehavior(playerAttackBehavior).getAmmo(%srcObj.tipo)); //this DONT work
echo(%dstObj.getBehavior(playerAttackBehavior).getMaxAmmo(%srcObj.tipo));//this DONT work
echo(%dstObj.getBehavior(playerAttackBehavior).getAmmo(1)); //this works
echo(%dstObj.getBehavior(playerAttackBehavior).getMaxAmmo(1)); //this works
}
}thx again!
#3
1) If they are being called.
2) If you are getting the parameters that you expect.
08/19/2010 (1:19 am)
Put echo-statements in your getAmmo and getMaxAmmo to see two things:1) If they are being called.
2) If you are getting the parameters that you expect.
function playerAttackBehavior::getAmmo(%this,%tipo)
{
echo( "In playerAttackBehavior::getAmmo." );
echo( " * %tipo = " @ %tipo );
return (%this.ammo[%tipo,1]);
}
#4
with this code:
"encontrada municion"
1.000
1.000
In playerAttackBehavior::getAmmo.
* %tipo = 1.000
//no answer
In playerAttackBehavior::getMaxAmmo.
* %tipo = 1.000
//no answer
In playerAttackBehavior::getAmmo.
* %tipo = 1
0 //good answer
In playerAttackBehavior::getMaxAmmo.
* %tipo = 1
4 //good answer
0 and 4 are values on my array, they are ok.
i have noticed he recieves %srcObj.tipo as a float, and probably i need integer to acces to the array.
thats the way i defined it,its wrong? is there any way to cast %srcObj.tipo as an integer?
thnx a lot again!
08/19/2010 (8:14 am)
thx again William!with this code:
echo("encontrada municion");
echo(%srcObj.tipo);
echo(%srcObj.ammo);
echo(%dstObj.getBehavior(playerAttackBehavior).getAmmo(%srcObj.tipo));
echo(%dstObj.getBehavior(playerAttackBehavior).getMaxAmmo(%srcObj.tipo));
echo(%dstObj.getBehavior(playerAttackBehavior).getAmmo(1));
echo(%dstObj.getBehavior(playerAttackBehavior).getMaxAmmo(1));"encontrada municion"
1.000
1.000
In playerAttackBehavior::getAmmo.
* %tipo = 1.000
//no answer
In playerAttackBehavior::getMaxAmmo.
* %tipo = 1.000
//no answer
In playerAttackBehavior::getAmmo.
* %tipo = 1
0 //good answer
In playerAttackBehavior::getMaxAmmo.
* %tipo = 1
4 //good answer
0 and 4 are values on my array, they are ok.
i have noticed he recieves %srcObj.tipo as a float, and probably i need integer to acces to the array.
if (!isObject(ammoItemBehavior))
{
%template = new BehaviorTemplate(ammoItemBehavior);
%template.friendlyName = "items de municion";
%template.behaviorType = "Item";
%template.description = "añaden municion de un tipo definido.";
%template.addBehaviorField(tipo, "type of ammo", U32, 0);
%template.addBehaviorField(ammo, "number of ammo", U32, 0);
}thats the way i defined it,its wrong? is there any way to cast %srcObj.tipo as an integer?
thnx a lot again!
#5
08/19/2010 (6:46 pm)
Instead of "U32", it looks like you just need to use "int".
#6
08/20/2010 (6:39 am)
i did before but theres no way, its so anoying ><!!!
Associate William Lee Sims
Machine Code Games