(beginner) How to add a "thirst" feature?

In my game, the player character will have to drink water every couple of steps to avoid heat stroke in the desert. The way I want to go about doing this is by having something in the Status tab labeled "Thirst" and it will go down every time the player enters a new room. When the counter hits zero, the player will die.

I have no idea how to go about doing this, and I honestly know nothing about coding to begin with. Just a simple, straightforward answer would be very appreciated :)


This should be a pretty simple thing to achieve. As you say you have no coding experience, I'll include screenshots of the GUI, as well as the code that they correspond to if you click 'code view'. Hopefully you'll be able to see how the two versions relate to each other.

I have no idea how to go about doing this, and I honestly know nothing about coding to begin with.

I'll go through this step by step. I don't know how much you already know, so I'll go over every detail. Sorry for the excessive wordage if you can already do a lot of this. But hopefully you'll understand how it works, so you'll find it easier to see a solution in future.

Even if you find that you prefer working with the GUI interface for scripts, it's still good to be familiar with code view, so you can use it to copy and paste code when discussing stuff on the forum.

Taking this step by step…

The way I want to go about doing this is by having something in the Status tab labeled "Thirst"

So first, you will want to create a thirst attribute. There are two different ways to do this: using script, or using the 'Attributes' tab. The Attributes tab doesn't exist in the online editor, so I can't give any more details about that method.

In the web editor, creating an attribute is as simple as giving it a value. You can put this script either in the game's start script, or in the object's initialisation script:

Set variable [game.pov.thirst] = [expression][100]
game.pov.thirst = 100

Here I've used the name game.pov.thirst to refer to an attribute of the player. You could alternatively use player.thirst (or whatever the name of the player object is), but there's a lot of cases where people have had problems because they changed the name of the player object, or allowed the player to switch between characters, and a script no longer works. So using game.pov is a good habit to get into; it always means the character that the player is currently controlling.

something in the Status tab

You can easily add thirst to the status attributes pane. You can add status attributes on the 'Player' tab of the game. I believe you can also do this on the 'Attributes' tab, but that isn't available in the web version.
Status attribute key: [thirst], value: [Thirst: !]
In this example the key is thirst (the exact name of your attribute), and the value is Thirst: !, which is what will be displayed to the player. the ! will be replaced by the current value of the attribute.

it will go down every time the player enters a new room

Simple enough. On the game's "Scripts" tab, there is a space for a script which will run every time the player enters a room.

Set variable [game.pov.thirst] = [expression][game.pov.thirst - 1]
game.pov.thirst = game.pov.thirst - 1

In this case, the attribute we're changing is game.pov.thirst, and we're setting it to game.pov.thirst - 1 - 1 less than its previous value.

When the counter hits zero, the player will die.

There are two ways you could do this. You could modify the roomenter script:

a few lines of code
game.pov.thirst = game.pov.thirst - 1
if (game.pov.thirst <= 0) {
  msg ("You have succumbed to heat stroke, and died.")
  finish
}

or you could put the if statement in a script attribute named changedthirst - this ensures that it will be checked every time the thirst attribute changes. I believe the Attributes tab has an option to add a change script to each attribute if you're using the desktop editor. In the web version, you would create it in the same place you set up the attribute:

game.pov.thirst = 100
game.pov.changedthirst => {
  if (this.thirst <= 0) {
    msg ("You have succumbed to heat stroke, and died.")
    finish
  }
}

Using a changescript like this has the advantage that if an attribute is changed in a lot of places, you don't need to include the code to check if it has hit zero every time.

have to drink water every couple of steps

I assume you will have an object like a water bottle, or similar. This would have a "drink" verb, which increases the player's thirst attribute. You've already got a script to reduce the attribute, so I think you would know how to increase it.

If there's anything I've missed, I'm happy to give a little more detail.


Excuse me. May I help?

This can be changed.

game.pov.changedthirst => {
  if (this.thirst <= 0) {
    msg ("You have succumbed to heat stroke, and died.")
    finish
  }
}

To this:

game.pov.changedthirst => {
  if (this.thirst <= 0) {
    msg ("You have succumbed to heat stroke, and died.")
    finish
  }
  if (thirst > 0 and thirst < 25) {
    msg ("You are suffering from thirst! Get water quickly!")
  }
}

Thank you, this was very easy to grasp and I've already learned a whole lot more about this website. :)))


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums