I need some help please? Stop -1 coins to stay at 0 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need some help please? Stop -1 coins to stay at 0

I use a game engine called buildbox 3d. I'm using JavaScript. I'm trying to stop my coin value going past -1 If player has used all coins then I would like it to stay at zero until new coins have be given. I can't seem to stop this -1 problem Here's an example: Function signal(name, value){ If(value){ Let amount = this.attribute('Amount'); This.scene().addScoreCoin('Amount'); } // This is the normal code then im trying to add If(amount == 0);{ This.attribute('Amount'); This.active = false; } } Any help would very much appreciated 👍👍

8th Jan 2019, 1:38 PM
leighton
leighton - avatar
6 Answers
0
In the function where you check for the amount of coin hold by the player you should put a conditional statment that check if the coins are less then 0, if so then you set the amount of coin equal to zero!
8th Jan 2019, 2:01 PM
Sekiro
Sekiro - avatar
0
Thank you Sekiro. I am leaning and hard to understand at the moment. Could you provide an example for me please? Thanks
8th Jan 2019, 2:08 PM
leighton
leighton - avatar
0
Mmh I dont know how buildbox works so I cannot provide a real code, but in Javascript you would do something like this: //variable that store coin amount var coin = 100; //now we need a function to check the amount of coin function checkCoin() { if(coin < 0) { coin = 0; } } so everytime the function checkCoin is called it will check if the coin amount is less the. 0 and if it is then it sets the coin amount back to 0!
8th Jan 2019, 2:21 PM
Sekiro
Sekiro - avatar
0
Look this is a code I wrote sometime ago, at line 225 I do something similar, when player use 1 food to heal, he will get 10 health point, if player has 95 health point and will use 1 food, he will gain 10 health point so health will become 105! To stop that from happening I set a conditional to check when use food if life goes over 100 then life will be sets to 100 no matter what! Basically the player has 95 healt, use 1 food gain 10 health, healt become 105 the function check health, health is greater then 100 so health will be set to 100 again. Give a look at it maybe it will help you out: https://code.sololearn.com/WeqfpL1EF0Fd/?ref=app From what I understand you need to do the same things, just check if coin are less then 0 instead of greater then 100!
8th Jan 2019, 2:31 PM
Sekiro
Sekiro - avatar
0
Thanks for your time Sekiro. I believe I have some work to do 😀👍
8th Jan 2019, 2:33 PM
leighton
leighton - avatar
0
You are welcome 😉 Happy coding!
8th Jan 2019, 2:56 PM
Sekiro
Sekiro - avatar