Trying to alter a specific values in a table using three diffrent functions
#gets the qauntty of a selected row
def get_deck_quant(select):
cursor.execute(f'SELECT quant FROM player_deck WHERE in_deck == {select} ')
resaults = cursor.fetchone()
return resaults[0]
#adds one to the selected card if it doesn't exceed the maxiumium allowed (specified in another table)
def deck_build(select):
indeck = get_deck_quant(select)
cursor.execute(f'SELECT max FROM all_cards WHERE id == {select} ')
maximiumget = cursor.fetchone()
maximium = maximiumget[0]
if indeck < maximium:
cursor.execute(f'UPDATE player_deck SET quant = quant + 1 WHERE in_deck = {select}')
con.commit()
#decreases the quantity of the selected card by one if it is above 0
def remove_card_deck(select):
if get_deck_quant(select) > 0:
cursor.execute(f'UPDATE player_deck SET quant = quant - 1 WHERE in_deck = {select}')
con.commit()
functions are called within this pygame loop and should move the button from one side of the screen to the other depending on whether the card has been added twice or has is no longer in the deck.
pygame.init()
screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption('goob')
clock = pygame.time.Clock()
cardbutton0 = pygame.image.load('card_place_holder.png').convert_alpha()
card_select0 = Button(150,125, cardbutton0, 0.45)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("black")
if card_select0.draw() == True:
if card_select0.rect.x >= 150 and card_select0.rect.x < 790:
quant = get_deck_quant(0)
if quant == 2:
print(quant)
card_select0 = Button(790,125, cardbutton0, 0.45)
else:
deck_build(0)
print(quant)
elif card_select0.rect.x >= 790:
if quant == 0:
print(quant)
card_select0 = Button(150,125, cardbutton0, 0.45)
else:
remove_card_deck(0)
print(quant)
pygame.display.flip()
clock.tick(60)
pygame.quit()
adding cards works fine but when i click the button after it has moved, 2 is still returned and doesn’t decrease.
both functions work independently without the logic
New contributor
Ziv Hammerman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.