Error when changing a attribute

I am creating a level up mechanic but got an error when attempting to add two points to it, this is my code.

if (player.xp = 10) {msg ("{colour:cyan:Level-Up!}")player.hitpoints = 60player.upgradepoint = player.upgradepoint + 2}    

This is the error:
Error running script: Error compiling expression 'player.upgradepoint + 2': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

What did I do wrong?


The attribute player.upgradepoint is something other than a number. It's probably null, which is used to mean "unknown".

To avoid this error, you could make sure you set the attribute to zero at the start, or check if it exists by doing something like this:

if (HasInt (player, "upgradepoint")) {
  player.upgradepoint = player.upgradepoint + 2
}
else {
  player.upgradepoint = 2
}

Log in to post a reply.

Support

Forums