Language…
8 users online: Cristian Cardoso, fsvgm777, JezJitzu, KoJi, Pink Gold Peach, playagmes169, sempf 84, stormitive - Guests: 250 - Bots: 395
Users: 64,795 (2,377 active)
Latest user: mathew

Custom block check whether blue switch palace has been beaten

I want my block to only work if the blue switch palace has been beaten, but I get the same result either way.

What am I doing wrong?

Code
!palRAM	=	$87	; one byte of free RAM, you may need to change this
!palID	=	$01	; the palette ID to change to (00 = original)

db $42
JMP Main : JMP Return : JMP Return 
JMP Return : JMP Return : JMP Return : JMP Return
JMP Return : JMP Return : JMP Return 

Main:
	LDA $1F29
	CMP #$00
	BEQ Deny
	LDA #!palID
	STA !palRAM
	LDA #$2B
	STA $1DFC
	
Deny:
	LDA #$2A
	STA $1DFC
	RTL
Return:
	RTL
Add an RTL to the end of "Main". Can also remove the CMP and change the BEQ to BNE (BNE automatically checks if the value in the accumulator is 0), as well as remove the RTL from "Deny", but those shouldn't pose a problem if left as is.
Still not working. I'm having weird behavior now. I put comments in the code.

Here is my code now.

Is there a way I can check and make sure the flag is getting set when i beat the switch palace?

Code
!palRAM	=	$87	; one byte of free RAM, you may need to change this
!palID	=	$01	; the palette ID to change to (00 = original)

db $42
JMP Main : JMP Return : JMP Return 
JMP Return : JMP Return : JMP Return : JMP Return
JMP Return : JMP Return : JMP Return 

Main:
	LDA $1F29
	BNE Deny
	LDA #!palID  
	STA !palRAM	;palette did not change neither before or after switch was pressed
	LDA #$2B
	STA $1DFC	;this sfx played before switch was pressed
	RTL
Deny:
	LDA #$2A
	STA $1DFC  	;this sfx played after switch was pressed
Return:
	RTL
The flag definitely gets set, but it appears to act the wrong way around for some reason I'm not sure of? Changing the BNE back to BEQ without re-adding anything else should work.
Code
db $42
JMP Main : JMP Return : JMP Return 
JMP Return : JMP Return : JMP Return : JMP Return
JMP Return : JMP Return : JMP Return

This is what you have at the top of your code. These JMP's dictate when your block runs its functions. They map as follows:

Code
db $42
JMP MarioBelow : JMP MarioAbove : JMP MarioSide
JMP SpriteV : JMP SpriteH : JMP MarioCape : JMP MarioFireball
JMP TopCorner : JMP BodyInside : JMP HeadInside

Notice how the only "JMP Main" in your code corresponds to MarioBelow - as you have it now, your block will only run if Mario touches it from below. I'm not much of a block whiz, but I'd try this:

Code
!palRAM	=	$87	; one byte of free RAM, you may need to change this
!palID	=	$01	; the palette ID to change to (00 = original)

db $42
JMP Main : JMP Main : JMP Main 
JMP Return : JMP Return : JMP Return : JMP Return
JMP Main : JMP Main : JMP Main 

Main:
	LDA $1F29
	BEQ Deny
	LDA #!palID  
	STA !palRAM	;palette did not change neither before or after switch was pressed
	LDA #$2B
	STA $1DFC	;this sfx played before switch was pressed
	RTL
Deny:
	LDA #$2A
	STA $1DFC  	;this sfx played after switch was pressed
Return:
	RTL

That way, the block should execute if Mario touches it from any side, or if he ends up within the block. If the block touches the cape, a fireball or a sprite, it will do nothing. (Also Meirdent is right, I changed the BNE back to BEQ.)

I should point out in advance that this code runs every frame the player is in contact with the block, and this block plays a sound effect - touching this block will try to play the same sound effect every frame, which probably won't work out too great.
Thank you all! I have it working now.

I actually only want it to work if you hit it from below. Like a question block.

I was concerned about the sound effect portion of the code. It works fine as is because if you hit it from below, you immediately fall back down away from the block.

Are there any safe guards that I should include just in case the player somehow touches the block for more than a frame?


You can check Mario's Y speed. It's only possible to have a negative (upwards) Y speed for one frame while touching the bottom of a block, so you can add a check like this to the top of the code:

Code
Main:
	LDA $7D
	BPL Return
	; rest of the code


Professional frame-by-frame time wizard. YouTube - Twitter - SMW Glitch List - SMW Randomizer