Python Forum
python seems to be skipping lines of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python seems to be skipping lines of code
#1
Hello! i wrote tetris in python using pygame the other day and am having a strange problem. There is a section of code that does not seem to run. here is the relevant function
def update():
    #time.time()
    global level, currTimeSD, currTimeBI, currTimeFD, currTimeSAC, timeShiftDown, timeFastDrop, timeBetweenInput, timeShiftAfterClear, kLeft, kRight, kDown, xCursor, yCursor, currMinoRot, currMino, swapMino, currMinoShape, swapMinoShape, alreadySwapped, minoActive, shiftAfterClear

    if time.time() < currTimeSD:
        currTimeSD = 0
    if time.time() < currTimeBI:
        currTimeBI = 0
    if time.time() < currTimeFD:
        currTimeFD = 0
    if time.time() < currTimeSAC:
        currTimeSAC = 0

    if shiftAfterClear == True:
        if time.time() - currTimeSAC >= timeShiftAfterClear:
            print("in shift after clear")
            currTimeSAC = time.time()
            shiftAfterClear = False
            shiftDownBoard()
            currMinoShape = 0
            currMino = generateRandomMino()
            minoActive = True
        return

    if time.time() - currTimeBI >= timeBetweenInput and anyKeyTrue():
        currTimeBI = time.time()
        if kLeft == True and xCursor != 0:
            if checkSafeShiftX(-1) == True:
                xCursor -= 1
        if kRight == True and xCursor != 9:
            if checkSafeShiftX(1) == True:
                xCursor += 1
        
        if kQ == True:
            if currMinoRot == 0:
                safe, newX = checkSafeRot(3)
                if safe:
                    xCursor = newX
                    currMinoRot = 3
            else:
                safe, newX = checkSafeRot(currMinoRot - 1)
                if safe:
                    xCursor = newX
                    currMinoRot -= 1
        if kW == True:
            if currMinoRot == 3:
                safe, newX = checkSafeRot(0)
                if safe:
                    xCursor = newX
                    currMinoRot = 0
            else:
                safe, newX = checkSafeRot(currMinoRot + 1)
                if safe:
                    xCursor = newX
                    currMinoRot += 1

        if kE == True and alreadySwapped == False:
            alreadySwapped = True
            if swapMinoShape == 0:
                swapMinoShape = currMinoShape
                swapMino = currMino
                currMino = generateRandomMino()
            else:
                swpms = swapMinoShape
                swpm = swapMino
                swapMinoShape = currMinoShape
                swapMino = currMino
                currMinoShape = swpms
                currMino = swpm
                xCursor, yCursor = generateStartCoord()
        
        if kUp == True:
            dropDownAndAdd()
            alreadySwapped = False
            checkCleared = clearBoard()
            if checkCleared == True:
                minoActive = False
                shiftAfterClear = True
                currTimeSAC = time.time()
            else:
                currMinoShape = 0
                currMino = generateRandomMino()
        if kEsc == True:
            print("Goodbye!")
            exit()

    if (time.time() - currTimeSD >= timeShiftDown) or (time.time() - currTimeFD >= timeFastDrop and kDown == True):
        currTimeFD = time.time()
        currTimeSD = time.time()
        if checkSafeShiftY() == True:
            yCursor += 1
        else:
            print("hi there", flush = True)
            addToBoard()
            for a in range(10):
                if board[a][0] == 1:
                    print("Sorry, you lose!")
                    exit()
            alreadySwapped = False
            checkCleared = clearBoard()
            print("whatup", flush = True)
            if checkCleared == True:
                print("genius", flush=True)
                print("whatup1", flush = True)
                tmpLevel = level
                level = 5 #int(linesCleared / 10)
                if tmpLevel != level:
                    if timeShiftDown - 0.08 < 0.03:
                        timeShiftDown = 0.03 
                    else:
                        timeShiftDown -= 0.08
                minoActive = False
                shiftAfterClear = True
                currTimeSAC = time.time()
            else:
                currMinoShape = 0
                currMino = generateRandomMino()
    return
down near the bottom of the code this block:

                print("genius", flush=True)
                print("whatup1", flush = True)
                tmpLevel = level
                level = 5 #int(linesCleared / 10)
                if tmpLevel != level:
                    if timeShiftDown - 0.08 < 0.03:
                        timeShiftDown = 0.03 
                    else:
                        timeShiftDown -= 0.08
does not run. when i move it up to the
if shiftAfterClear == True:

block near the top of the function everything runs fine. Any idea what is happening? thanks!
Reply
#2
tmpLevel = level
level = 5 #int(linesCleared / 10)
This is not your problem, but the second line of code here overwrites the previous
remove line 105

before if timeShiftDown - 0.08 < 0.03:
add: print(f"in loop, tmpLevel: {tmpLevel}"

show results
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File loop curiously skipping files - FIXED mbk34 10 814 Feb-10-2024, 07:08 AM
Last Post: buran
  What are these python lines for? What are tey doing? Led_Zeppelin 7 1,629 Feb-13-2023, 03:08 PM
Last Post: deanhystad
  Regular Expression search to comment lines of code Gman2233 5 1,697 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  Skipping line in text without Restarting Loop IdMineThat 4 1,498 Apr-05-2022, 04:23 AM
Last Post: deanhystad
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,134 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
  Running a few lines of code as soon as my timer ends nethatar 3 2,429 Feb-26-2021, 01:02 PM
Last Post: jefsummers
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,269 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Making new lines of code AvioxyYT 1 1,814 Jan-22-2021, 07:02 PM
Last Post: buran
  Repeating lines of code by an input Josh_Albanos 3 2,426 Oct-15-2020, 01:04 AM
Last Post: deanhystad
  Beginner: I need help understanding few lines of a code. hop_090 1 1,697 Sep-07-2020, 04:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020