Ask coding questions

← Back to all posts
How to make a point system
LioxLynx (0)

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.

Answered by LukeWright (114) [earned 5 cycles]
View Answer
LukeWright (114)

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

LukeWright (114)

@LioxLynx Click the checkmark next to my comment if this helped!

InvisibleOne (2672)

actually, the variable doesn't revert back to what it was, you just create another variable inside of the function, they are actually totally different variables. @LukeWright

Muffinlavania (1510)

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