I would like to save the int variable "totalbal" into a text file, so it doesn't resets the variable everytime you quit.
import pygame, sys, time
from pygame.locals import *
cpsecond = open("clickpersecond.txt", "r+")
cps = int(cpsecond.read())
baltotal = open("totalbal.txt", "r+")
totalbal = int(baltotal.read())
pygame.init()
while True: # main game loop
...
if event.type == MOUSEBUTTONDOWN:
totalbal += cps
savebal = str(totalbal)
str(baltotal.write(savebal))
print("Your current money is", savebal, end="\r")
pygame.display.flip()
clock.tick(30)
When you click, it increases the variable "totalbal" by +1, when you click 8 times, it saves in the text file like 012345678, i tried to fix it with:
int(baltotal.write(savebal))
but it didn't worked out.
<<< Your current money is 1
<<< Your current money is 2
<<< Your current money is 3
<<< Your current money is 4
<<< Your current money is 5
<<< Your current money is 6
<<< Your current money is 7
<<< Your current money is 8
#The text file output: 012345678