How to I use counters to set flags?

So I'm trying to use a counter to set a flag. Like if the player drinks too much, he becomes drunk. So each drink adds +1 or +3 depending on the strength of the drink. And also if the player's counters reaches a certain point, another flag is set to "really drunk" or something like that.

The problem I'm having is that, when the player drinks a shot, it is setting the counter higher, but when I use the 'if' function for "if player counter reaches 20, then flag 'drunk' is set," it's not setting the flag, no matter what I try. Am I not doing it right? is there a better way to do it?

I use {if player.flag.flagname:text} in the room descriptions, which is why i want to use flags.


So your code is something like:

player.drinks = player.drinks + 1
if (player.drinks > 20) {
  player.drunk = true
  if (player.drinks > 40) {
    player.reallydrunk = true
  }
}

and then in a room description you have something like:

{if player.drunk:The room is swaying slightly because of all those drinks.}

That should work. If it isn't, tell us what's different in yiur code.


If you wanted to shorten the script, you could also split it up a little. This is often a simple way to make large projects easier to work with.

When you make a drink, you would give it a 'drink' verb including the line:

player.drinks = player.drinks + 1

and when you make a stronger drink, you could include something like:

player.drinks = player.drinks + 3

but you don't need to copy the rest of the code into both of these. You don't need to repeat the if statements in the verb for every different drink.

Instead, you could go to the 'Attributes' tab of the player, and create a script attribute named changeddrinks. Quest will automatically run this script every time the drinks counter changes. So you could fill it with something like:

if (this.drinks > 20) {
  this.drunk = true
  if (this.drinks > 40) {
    this.reallydrunk = true
  }
}

or, to make that script a bit shorter while doing the same thing, you could make it:

player.drunk = (player.drinks > 20)
player.reallydrunk = (player.drinks > 40)

So, I don't know much about code, so I'm not sure how to incorporate what you said into my game. What exactly I'm doing--which I forgot to put in my first question--is that I made an attribute for the player named 'drunkeness' and it's an integer. Then I have a command link in my room that when the player clicks on it, he drinks from a bottle of vodka and adds +1 to his drunkeness attribute.

Then I try to use an 'if' to say "if player attribute drunkeness >= 5 then player flage drunk is set on" which in turn would show that little tidbit of description on the room. It's not working.

Though if it helps, this is the code view of the command I'm using:

msg ("You take a drink of vodka.<br/><br/>[press space bar]")
player.drunkeness = player.drunkeness + 5
wait {
  MoveObject (player, room)
}
if (GetInt(player, "player.drunkeness") >= 5) {
  SetObjectFlagOn (player, "drunk")
}

I got it to work! I copied your first code and put it in to mess around with it, and it actually sets the flag. Thank you so much for your help. You don't know how long this has been bugging me.


So, I don't know much about code, so I'm not sure how to incorporate what you said into my game. What exactly I'm doing--which I forgot to put in my first question--is that I made an attribute for the player named 'drunkeness' and it's an integer.

I assumed something like that. In my examples I called the attribute drinks, which should be the only thing you need to change to make my examples work.


In your code sample you've got GetInt(player, "player.drunkeness")

That should be either GetInt(player, "drunkeness") or just player.drunkeness.

The former is the code the GUI would generate; the latter the way most programmers would write it (marginally more efficient, but less obvious what it means until you get used to reading code)


Log in to post a reply.

Support

Forums