Is there a way to set a maximum and a minimum for a attribute
Atokrad
12 Mar 2021, 05:34For an attribute like health is there a way to ensure that a player can't get more than the maximum intended amount of health but still be able to up that later in the game? For example, you can give the player 40 hitpoints but when they level up you can up that to 60 without letting the player go above either amount.
mrangel
12 Mar 2021, 09:27The normal way to do this would be to have two attributes, health
and maxhealth
. Then you'd give health
a changescript (which is actually just a script attribute named changedhealth
). You'd make it something like:
if (this.health > this.maxhealth) {
this.health = this.maxhealth
}
else if (this.health <= 0) {
// whatever code you want to use
// for telling the player they are dead or KO
}
Atokrad
13 Mar 2021, 00:23How would I sent the player to a room, I want to let a player have a save point in an area that can be changeable, I was thinking about using an attribute but I don't think that would work.
mrangel
13 Mar 2021, 01:22If you want to send them to a room, just move them to that room.
There's a built in function to do that:
MovePlayer (kitchen)
although that's actually the same as
MoveObject (game.pov, kitchen)
which is the same as
game.pov.parent = kitchen
(the first one is obvious what it does when you read it, which is why that's the code the GUI creates. The last one is the most efficient, but might be harder to understand until you get used to it. game.pov
is an attribute that contains the current player object)
If you want to send them to a different place each time, you can just store the room in an attribute. For example, when the player uses a save point, you would run the script:
game.savepoint = game.pov.parent
and then to go back there, you would use:
game.pov.parent = game.savepoint