Stop object counter from going into the negatives?

So here is my situation, and im sorry for posting so much lol.

For this example I'm going to use vodka.
I have a status attribute called vodka tied to an integer.
I also have a command called drink which demands that I have vodka AND coke in order to actually drink.

But if i drink all my vodka, I want it to tell me "hey, you have no more vodka" when the counter reaches zero.

What is confusing me is, where do implement this?
On the command drink, the player attribute? or the coke and vodka attribute? or all 4?

Thanks for your help, sincerely... a newb.


There's three main ways to do it.
If the vodka attribute is only used by the drink command, then you would probably put the message as part of that command. As the command script is already running, it's more efficient to include extra checks there, rather than calling another script.

If there are multiple ways in which vodka can be used, it could be beneficial to have a single script which makes sure you have some, rather than having to write the same code multiple times.
One way to do this would be using a changescript. If the player has a script attribute named changedvodka, it will be run every time their vodka attribute changes. This is the standard way to prevent a counter (such as health) going over a maximum or under a minimum. So you could make the script something like:

if (this.vodka < 0) {
  this.vodka = 0
}
else if (this.vodka = 0) {
  msg ("You have run out of vodka.")
}

Another option would be to make a function. This gives you the benefits of being able to check whether the player has enough vodka before letting them use the command, while also meaning that you don't need to replicate the same code.

Hope that makes some sense.


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

Support

Forums