[Solved] Input script fired too often

roedesh

New member
UPDATE: It was because of the Mesen turbo settings

Hi, I'm having some trouble with one of my input scripts. I want to toggle a variable when the user releases the A button.

Code:
    LDA myVar
    CMP #$01
    BEQ +
    LDA #$01
    STA myVar
    RTS
+
    LDA #$00
    STA myVar
    RTS

...but if I keep pressing A, it keeps toggling the variable.
In the Input Editor it is defined like this
Code:
MainGame: Release A: Player 1:0 - Path/To/Script.asm

I'm still learning 6502 asm so if there is a better way for toggling a boolean, please let me know.
 

dale_coop

Moderator
Staff member
Your code is correct.

Note that instead of checking if "01" you could also check if "00", the code is shorter:
Code:
    LDA myVar
    BEQ +	;; if myVar is equal to zero, branch on +
    LDA #$00
    STA myVar
    RTS
+
    LDA #$01
    STA myVar
    RTS
 

roedesh

New member
Thanks for the code sample!

After some more fiddling around I noticed that it only happens when I assign my script to either the A or B button.
If I assign my script to one of the arrow buttons, it works just fine, and only gets fired once per key press.

I'm using the Mesen emulator btw (if that helps).
 

dale_coop

Moderator
Staff member
Maybe it' the way NESmaker is dealing with A and B inputs.
Not sure we can do anything for that.
 

Mugi

Member
check in mesens config that you are not using "turbo" buttons, i know more than one person on this forum who fell for this trap.
turbo buttons just keep infinitely repeating their thing if you press it, and generally a press registers as 2 or 3 presses really easily.
 

roedesh

New member
Mugi said:
check in mesens config that you are not using "turbo" buttons, i know more than one person on this forum who fell for this trap.
turbo buttons just keep infinitely repeating their thing if you press it, and generally a press registers as 2 or 3 presses really easily.

You are a lifesaver! It was indeed because of the turbo settings. I set it to the slowest setting and now there are no more problems.

SpiderDave said:
to toggle a variable between 0 and 1, you can use this
Code:
LDA myVar
EOR #%00000001
STA myVar
RTS

Short and sweet. Thanks!
 
Top Bottom