Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] ROLL function
I am making a dice game, here is my roll function.
What I want to happen is for the loop to repeat 9 times(or 10 I can't tell) and each time pick a different dice side to blit to mimic rolling the die. Instead, whats happening is it generates a random side on both die like it should and then only blits it the last time.
def ROLL():
        rolltime = 1                      #rolltime is a variable that goes up by one each time it loops
        while True:
            if rolltime <= 10:      
                DiceRoller1 = random.choice(Dice)    #Dice is a list of 6 images, one of each side
                DiceRoller2 = random.choice(Dice)    # in the game there are two dice you roll
                screen.blit(DiceRoller1,(0,0))             #this and the next line are whats giving me issues
                rolltime += 1
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
            else:                           #if rolltime is over ten the loop breaks
It makes sense if you think about it. It does 10 iterations of the while loop in a split second. Of those fractions of a second your eyes can only see the last one due to it being persistent.

It appears you need to rethink your entire game structure. You should only have 1 event loop in all of your code for your entire game. I am assuming you do it the method in which has an event loop for each object, function, etc. If so, the name "Sentdex" should ring a bell and this is a bad structure.

Im not sure what you are doing exactly. But if you want to retain the random information of dice, you have to save it before the while loop. Aside from that, there has to be some event to switch between all these dice. The way you have it fractions of a second events change it, you need something much slower for human eyes to catch....like a keypress from the user to switch, or a much longer delay, like a .5 second, etc.
ok, what should I do? Decrease the clock.tick to 2 FPS, add a 
, or something else completely?

p.s. I do watch Sentdex for tutorials. If you think he's teaching bad structure do you have anyone you would recommend?

Scratch that I just went on my code and tried the
pygame.time.delay() and then tried the slower frame rate. What happened was that it wasn't it bliting repeatedly so you couldn't see it. It actually waited until the end and blited once. Why?
This shows the main list of why sentdex structure is bad. The main reason is the the nested while loops as the issue in which creates spaghetti code later as the game increases in size. It also shows and example of sentdex along with a customization of how it should be for those that use sentdex to hae a comparison of what they know.

Im not really going to try to decipher the workings of how sentdex structure works. The way its coded needs to be completely reworked.

Unfortunately there are not a lot of tutorials for pygame, especially youtube videos. My suggestion would be to go slow and do numerous tutorials from different sources. In this way you obtain different information and different methods, while still getting (if you want it) the youtube experience.

There are various tasks used as an example on mekires repos. However they are examples, not tutorials. They use a good structure and OOP. You can find varying examples from simple mouse movement to full games, etc.

Kids can code tutorial videos. They arent just for kids though.
ok, thanks

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)