#๐Ÿ”’ Matching Game (in gui): 2nd card flipping back over instantly

110 messages ยท Page 1 of 1 (latest)

crystal dockBOT
#

@barren echo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

elfin sparrow
#

i think its something to do with show_card()

#

im talking about the if conditions

#

also this doesnt match what your pastebin has

#

can you tell me about your flipped logic

#

i think it should be in a loop

#

got it

#

it means i have flipped one card

#

ok so now there are 2 cards flipped

#

just use time?

#

time.sleep()

#

no in your check_match

#

you have use 1 second

#

increase it maybe?

#

what stops?

#

its because in your check_match method

#

you mention sleep before making it gray

#

wait no

crystal dockBOT
#

Hey @barren echo!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
elfin sparrow
#

just try it

#

dont forget to keep your old code

#

wait

#

where are you exactly calling the method show_card?

#

its in the load_card() let me see

#

yes

#

would you mind sharing your cs50 so i can try running the code myself

#

just copy paste the code

#

oh wait its a module

#

yep

#

this is the same code

#

oh i dont have cs50

#

imma just visually try finding whats wrong

#

im not that good at python

#

maybe we should wait for some expert

#

till then ill try

#
def show_card(row, col):
    global first
    global second
    global flipped
    buttons[row * 18 + col].config(text=board[row][col])
    time.sleep(0.5)
    flipped += 1
    if flipped == 1:
        first = (row, col)
    if flipped == 2:
        second = (row, col)
        flipped = 0
        time.sleep(1)
        check_match()```
can you try this? @barren echo
#

so when you click on the first card, it shows properly?

#

now on clicking the second, can you tell me what happens? with your original code, not mine

#

showing the grey card?

#

i see

#

@barren echo what are you checking in the first condition and what in the second?
if first != second:
if board[frow][fcol] == board[srow][scol]:

#

mhm

#

and in the second?

#

why do you need 2 conditions

#

like you are using 2 if statements

elfin sparrow
#

if first != second:
if board[frow][fcol] == board[srow][scol]:

#

i think either condition would get the job done, no?

#

are you sure you have indented the else block properly

#

im stumped

#

everything looks like its supposed to work

#

hold on im calling someone

#

nobody's listening ๐Ÿ˜ญ

tepid sphinx
#

@barren echo do you mind re-pasting the code?

#

the paste expired

elfin sparrow
#

i got you 2 people now

marsh sandal
#

I'm here. What's the problem?

#

ewww globals

elfin sparrow
elfin sparrow
marsh sandal
#

Can I get the code for cs50?

#

I'm trying to run your code so I can try to debug it

#

But I cant because no cs50

#

Pastebin

elfin sparrow
marsh sandal
#

Cuz right now I'm getting this:

line 1, in <module>
    from cs50 import get_string, get_int, get_char
ModuleNotFoundError: No module named 'cs50'
elfin sparrow
#

cs50 gui or whatever it is

tepid sphinx
#

!pip cs50

crystal dockBOT
#

CS50 library for Python

Released on <t:1702872370:D>.

marsh sandal
#

ah ok

#

I thought its a manual file

#

Didn't expect an actual package

elfin sparrow
marsh sandal
#

Its OK I got it

marsh sandal
#

It looks like none of the cs50 functions are being used in this script

elfin sparrow
marsh sandal
#

Are you supposed to?

marsh sandal
elfin sparrow
#

ok

marsh sandal
elfin sparrow
#

oh damn

marsh sandal
#

then its useless?

#

Are you taught to use globals in Python from CS50 or is that because someone suggested you to use globals? @barren echo

#

I think its fine for now. I'm able to "run" the code for now

elfin sparrow
#

can you give your latest code, the one i have shows multiple cards at once

marsh sandal
#

Second card does show up but it quickly hides it if its incorrect

#

If it matches, its grayed out

scarlet sapphire
#

whats the issue?

marsh sandal
#

it does

scarlet sapphire
#

you cant use time.sleep in pygame

#

in games in general

elfin sparrow
#

it works when i choose 2 correct ones, but the second one still doesnt show

scarlet sapphire
#

this would be much easier in pygame

#

pygame is python

#

idk tkinter but I would guess you measure frames

#

if you are running at 60fps, after 30 frames 0.5 seconds has passed

#

otherwise you find a way to import an animation

marsh sandal
scarlet sapphire
#

it has a main loop

#

so yes it does

#

in the video it shows the guy defining a clock function which compares the current time to the start time to see the duration of time passed and that function is passed into the mainloop as a command

#

watch the video

#

it shows exactly how to do it

#

interesting

#

i dont use tkinter so idk but if it works then the issue is solved?

crystal dockBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.