Intro
I'm having a very hard time on my first game, all of that because i dont know how to send an path as an argument that can be referenced. Onto the problem, i have this Text class that does everything text related.
class Text:
textfont = pygame.font.SysFont("monospace", 20)
# this is the place where text obects are stored at
textcount = 0
textwheel = []
# this is a method that receives arguments and creates a text object out of them
# that object is put inside the list above
@staticmethod
def createtext(text, posx, posy):
Text.textwheel.append(Text.textcount)
Text.textwheel[Text.textcount] = Text(text, posx, posy)
Text.textcount += 1
# path and text are almost the same thing
# path is supposed to hold the actual path to the object i want to reference every frame
# whilst text is the actual text version that is to be displayed
def __init__(self, text, posx, posy):
self.path = text
self.text = str(self.path)
self.texposx = posx
self.texposy = posy
self.surface = Text.textfont.render(self.text, True, (0, 0, 0))
# every frame a function runs through the list and updates the text to be the str version of the path
@staticmethod
def txtupd():
for textnum in Text.textwheel:
textnum.text = str(textnum.path)
textnum.surface = Text.textfont.render(textnum.text, True, (0, 0, 0))
Window.window.blit(textnum.surface, (textnum.texposx, textnum.texposy))
The problem is, when i try and create an object with certain arguments, it doesnt send a path, it sends just a value instead, Example:
# player input
Text.createtext(Input.playerinput, 50, 50)
Text.createtext(' W S A D', 50, 20)
# player cordinates
Text.createtext(Player.playerwheel[0].posx, 500, 20)
Text.createtext(Player.playerwheel[0].posy, 500, 50)
here i ask it to create texts with the current player input (list), and the player cordinates (x and y both ints), the thing is, when i send it the player cordinates (int), it just gets that value and keeps referencing that, contrary to when i send it the playerinput list, that one gets dinamically referenced and updated every frame.
here are the playerinput together with the player cords
class Input:
playerinput = [False, False, False, False]
class Player:
playercount = 0
playerwheel = []
@staticmethod
def createplayer():
Player.playerwheel.append(Player.playercount)
Player.playerwheel[Player.playercount] = Player()
Player.playercount += 1
def __init__(self):
self.posx = 200
self.posy = 200
self.spdx = 0
self.spdy = 0
self.color = (0, 0, 0)
I just want to be able to send paths to variables so that they can keep being referenced dinamically and be updated accordingly.
whole code in case u want to mess with it(you'll need the pygame library doe):