Skip to content
Advertisement

How do I make my stash function work? Every time I write “stash” it responds with “You have 0 Diamonds”. Although I have ran mine several times

This is my code:

JavaScript

The possible commands are Stash, Mine, and Time, but time doesn’t do anything yet. It would be very helpfull if every time I run Stash it didn’t show “You have 0 Diamonds”

Advertisement

Answer

Your code has multiple issues, starting with concept and style and ending with the actual fulfillment of the task. I reworked your code so Mine and Stash work logically (leastwise for me).

Disclaimer: the code below is still wrong on multiple points, but I want to post it in this form in order to be understandable for OP.

JavaScript

What I’ve changed:

  • Your global variables are now global inside your functions. So they keep their values between cycle’s loops.
  • Mine now firstly obtain random Mined value, this value shown to the user, and then it’s added to Mining. So if you mined several times, you lose nothing.
  • Stash now resets Mining to 0, so mined once wouldn’t be added to stash several times.

Not sure how Time and MT should work, so I left them untouched.

What you should change (and also learn):

  • General structure. If you have some data united with some logic, most probably it’s a class. You have to learn what it is and how you should use it for tasks like this, and you wouldn’t have such strange situations with variable scopes.
  • Function concept. Maybe you feel some things, but you definitely don’t understand them.
  • Python code style. Here is quite easy to read intro.
Advertisement