0

Variables are so baaaaaaad

I want to make a game that when you click on the play button you have some chances to have rewards(like a box openning like CSGO or etc...) and then you can see yours rewards at the left(for exemple if you get 3 money there will be show "💰 money" at the left) But my problem is when you got your reward and you want to replay, the variable "money" disappears and reset at 0 money. So if you get 2 money and after you get 3 money more you"ll don't have 5 money in the total but you"ll have 3 money in the total

8th Feb 2018, 8:48 AM
Valkyrion
Valkyrion - avatar
5 Antworten
+ 9
If you need help, post the code.
8th Feb 2018, 10:10 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
coming from a c++ background, my mind tells me a static variable is the answer to your issue here. This may help in getting the results you require: https://stackoverflow.com/questions/1535631/static-variables-in-javascript
8th Feb 2018, 12:24 PM
jay
jay - avatar
+ 3
https://code.sololearn.com/W4VKE2d5Mhrs/?ref=app
8th Feb 2018, 11:55 AM
Valkyrion
Valkyrion - avatar
+ 2
Because when you played for the second time the variable "money" was reset as if by magic at 0
8th Feb 2018, 8:50 AM
Valkyrion
Valkyrion - avatar
0
I love programming
8th Feb 2018, 11:20 AM
Njimukara