How to make a point system
I was wondering how to make a point system.
I've tried using a "Point" variable and changing it to its current state by one every time the player wins but it seems just to show 1 every time since at the beginning I set points to zero but even then, I can't seem to find a way to make a point system.
Since you are not using global variables or classes, the values revert to the last thing you set it to after the function is done. To combat this, I usually use classes or global variables.
to use global variables, simply put
global playpoints = 0 global item_num = 0 global random_num = 0 global robot_done = false global player_done = false global winner = None global player_input = None
This ensures that the variables that you change inside of the functions, stay the value that you changed it to.
To use classes simply do:
class vars: playpoints = 0 item_num = 0 robot_num = 0 robot_done = false player_done = false winner = None player_input = None
To call a class variable, simply do
print(vars.playpoints) print(vars.item_num) print(vars.robot_num) print(vars.robot_done) print(vars.player_done) print(vars.winner) print(vars.player_input)
If you want to change the
Point variable in a function (anything with
def), you are going to have to
global it at the top of the function.
So for example, if you want to change points in the
declare function, just put this one line at the start
def declare(winner, playpoints, player_input, player_done): global playpoints
That way you can edit the variable in the function, which should just work with your commented lines on 149,150,155,and 156