Once a value reaches zero

Joined
Dec 12, 2021
Messages
2
Reaction score
0
Hey all,

I am trying to create a code so that if I try to purchase something for say 20 gold, if I have 19 gold, it won't allow the purchase. Instead, my code keeps allowing me to go into the negative integers... Help! :)
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
I can't give exact advice without the code in question, but just do an if statement before the transaction.

JavaScript:
if (playerGold >= cost){
    playerGold -= cost;
} else {
    // Return error, etc
}
 
Joined
Dec 12, 2021
Messages
2
Reaction score
0
I can't give exact advice without the code in question, but just do an if statement before the transaction.

JavaScript:
if (playerGold >= cost){
    playerGold -= cost;
} else {
    // Return error, etc
}


Ahhhhhh! I had my brackets in the wrong placement with a "return false" and "null" attempts. Thank you! I knew it wasn't far off!

For the last 2 hours I've been trying to figure out how to put an inventory on the screen. When I purchase a fish, I want displayed "fish: 1" and go up with the more purchased... I'm new to this but loving it!
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
I'm glad you're enjoying it! If you have any more questions, just create a new post and we'll try to help out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top