Author Topic: Player Datablocks  (Read 1049 times)

There is an error around %player.getdatablock() and i cant figure it out. Help?
Code: [Select]
package PlayerBomb
{
function armor::onTrigger(%this,%player,%slot,%val)
{
if(%slot $= 4 && %Player.getdatablock() $= BombArmor)
{
centerprintall("\c2True");
%Player.kill();
}
else
{
centerprintall("False");
}
Parent::onTrigger(%this,%player,%slot,%val);
}
};
ActivatePackage(PlayerBomb);

Do you need quotes around the 4 and BombArmor? Or does Torque automatically recognize them as strings? Double or, would you need to change $= to == because they aren't strings? These are my only suggestions which are not valid until someone experienced confirms it.
« Last Edit: June 25, 2009, 03:52:46 AM by lilboarder32 »

Show us the part that makes BombArmor.

You may want to use .getDatablock().getName()

Do you need quotes around the 4 and BombArmor? Or does Torque automatically recognize them as strings? Double or, would you need to change $= to == because they aren't strings? These are my only suggestions which are not valid until someone experienced confirms it.

You only need quotes if there's more than one word;
type this in the console and see for yourself:
echo(Cat $= Cat); (returns 1)
echo(Big Cat $= Big Cat); (Syntax Error)
echo("Big Cat" $= "Big Cat"); (returns 1);

Whether or not it's good practice or not to always use quotes when checking strings, I would of thought so but I honestly can't say.
« Last Edit: June 25, 2009, 08:03:50 AM by MrPickle »

It works thank you to Chrono.

You only need quotes if there's more than one word;
type this in the console and see for yourself:
echo(Cat $= Cat); (returns 1)
echo(Big Cat $= Big Cat); (Syntax Error)
echo("Big Cat" $= "Big Cat"); (returns 1);

Whether or not it's good practice or not to always use quotes when checking strings, I would of thought so but I honestly can't say.
Oh, ok thanks!

Also, I think "$=" is case sensitive. To manipulate strings in order to get rid of this effect, you can use:

strupr(string) to convert the string to all caps

and then there's

strlwr(string) that converts the specified string to all lower cases.

Also, I think "$=" is case sensitive.

It's not;
echo("cat" $= "CAT"); (returns 1)
« Last Edit: June 25, 2009, 04:25:18 PM by MrPickle »

Oh yeah, thats only strcmp or something like that, it's used to compare strings.