1

I'm coding a microbit game for a school assignment and decided to ripoff Friday Night Funkin, which is a game where you have to play a song as accurately as possible. I've tried to code in this accuracy in my ripoff by getting more points the more accurate you are. The problem is there is a small pause between each note, and the pause is noticeably longer if you don't press the button to "play" the note.

Original Example Code:

basic.show_leds("""
        . . # . .
        . . . . #
        # . . . .
        # . . . .
        . . . . #
        """)
    Timer_3_Accuracy(300)
    Overall_Timer(300)

Original Function Code:

def Overall_Pause(num: number):
    global Overall_Timer
    basic.pause(num - Overall_Timer)
    Overall_Timer = 0

def Timer_3_Accuracy(num: number):
    global Timer_Three, Overall_Timer, Score
    while not (input.pin_is_pressed(TouchPin.P2)):
        basic.pause(1)
        Timer_Three += 1
        Overall_Timer += 1
        if input.pin_is_pressed(TouchPin.P2) or Overall_Timer == num:
            break
    if Timer_Three <= 125:
        Score += 50
    elif Timer_Three > 125 and Timer_Three <= num:
        Score += 30
    Timer_Three = 0

I then simplified it so there wouldn't be as many functions because I thought was a processing power issue but it hasn't changed anything. I just added this to the accuracy function and took out the Overall_Pause function:

basic.pause(num - Overall_Timer)
Overall_Timer = 0 

Does anyone have any recommendations? What am I doing wrong here? Would I need to reconfigure the while not function so it isn't as redundant?

Thanks in advance

EDIT: A related question, how would/is there a way to measure two accuracy points at once if your song has two "notes" at the same time?

  • 1
    I couldn't get the code you've posted to run. It is best to post code that is [a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) as result I can't test what you have posted. I would suspect the `while` loop is the issue. I think this is the Python in MakeCode so I would use the `def on_pin_pressed_p2():` functionality – ukBaz Jun 23 '21 at 06:20

0 Answers0