Locked Door Returns When Re-entering Screen

twin paradox

New member
After watching all of the tutorials and scouring many, many forum posts I am still having trouble with one mechanic that I need in my game. First off, I am using the Simple Platformer Module and NES Maker Version 4.1.5. I managed to successfully create a key object that uses a Powerup script and the HUD seems to update properly when I pickup the key. I then used the Locked Door script and assigned it to tile type #07. I had to uncomment a bunch of lines in the locked door script and now I am able to use the key on the locked door and have it change the locked door tile type to my #00 type tile (walkable) so that I can pass through. The only problem is that when I return to the room with the locked door, it is still there. I have tried uncommenting the "TriggerScreen screenType" line in the locked door script as the comments suggest to do but if I do, it gives me a "Branch out of Range" error when I try to compile the game.

Here are a few relevant things-

My User Constants:
User Constants.PNG

My Script Settings:
Script Settings.PNG

My Background Tileset that contains the locked door tile (it's just a yellow square placeholder for now):
Locked Door Index.PNG

My Locked Door Script:
Code:
;;; SOLID
;;;This is how to inform a solid collision.
;;; You can also add this to the end of
;;; any tile type if you want it to have an effect AND
;;; be treated like solid.
;;; You could also check to see if it is a non-player object,
;;; and only return solid if it's a not player.  This would
;;; cause monsters to treat things like spikes or ladder or fire
;;; as solid while the player is able to interract with it.

;;; RIGHT NOW, this changes to the underSecret type tile.
;;; And it changes to the 00 type (walkable) collision.
;;; to change this to a different collision type, for instance a warp,
;;; change the first argument in the ChangeTileAtCollision macro below.

	LDA #TILE_SOLID
	STA tile_solidity
	
	;; if you want it solid, declare it at the end
	

	
	;; is collision position loaded into y?
	 CPX player1_object
	 BNE +
	 LDA myKeys
	 SEC
	 SBC #$01
	 BMI +
	 STA myKeys


		 LDA myKeys
		 LDA #$01 ;; amount of score places?
		 STA hudElementTilesToLoad
		 LDA DrawHudBytes
		 ORA #HUD_myKeys
	 STA DrawHudBytes
	 ChangeTileAtCollision #$00, underSecret
	
	; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	; ;;; IF YOU WANT THE LOCK TO STAY GONE, Trigger the screen.
	; ;;; if not, comment this out.
	TriggerScreen screenType
	;PlaySound #sfx_emptySFX
	
+
Please let me know what relevant information you would like me to share if the solution is not obvious. Thank you!
 

dale_coop

Moderator
Staff member
You figured it out, you need to trigger the screen in order to have the tile removed (when re entering).
To fix branch out of range error, you need to reverse the conditions...
For example a
Code:
	BNE +
	;; do complicated stuffs
	+
Would become
Code:
	BEQ ++
	JMP +
	++
	;; do complicated stuffs
	+


Here's your script, modified:

Code:
;;; SOLID
;;;This is how to inform a solid collision.
;;; You can also add this to the end of
;;; any tile type if you want it to have an effect AND
;;; be treated like solid.
;;; You could also check to see if it is a non-player object,
;;; and only return solid if it's a not player.  This would
;;; cause monsters to treat things like spikes or ladder or fire
;;; as solid while the player is able to interract with it.

;;; RIGHT NOW, this changes to the underSecret type tile.
;;; And it changes to the 00 type (walkable) collision.
;;; to change this to a different collision type, for instance a warp,
;;; change the first argument in the ChangeTileAtCollision macro below.

	LDA #TILE_SOLID
	STA tile_solidity
	
	;; if you want it solid, declare it at the end
	

	
	;; is collision position loaded into y?
	 CPX player1_object
	 BEQ ++
	 JMP +
	 ++
	 LDA myKeys
	 SEC
	 SBC #$01
	 BPL ++
	 JMP +
	 ++
	 STA myKeys


		 LDA myKeys
		 LDA #$01 ;; amount of score places?
		 STA hudElementTilesToLoad
		 LDA DrawHudBytes
		 ORA #HUD_myKeys
	 STA DrawHudBytes
	 ChangeTileAtCollision #$00, underSecret
	
	; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	; ;;; IF YOU WANT THE LOCK TO STAY GONE, Trigger the screen.
	; ;;; if not, comment this out.
	TriggerScreen screenType
	;PlaySound #sfx_emptySFX
	
+
 

twin paradox

New member
Thank you so much! There is still one small problem. I no longer get an error and the screen does trigger after unlocking the door. But when I return to the room with the locked door, the locked door tile is still there (although it has a null tile type and can be walked through). Any ideas on how to not only change the tile type of an unlocked door but also the tile itself?
 

dale_coop

Moderator
Staff member
Your "TILE_INDEX_LOCK" constant value (in "Project Settings > User Constants") is correct, so I guess is just a script that is not assigned.

Check your "Project Settings > Script Settings", select the "Handle Triggered Tiles" element and assign the "CheckTriggeredLoads.asm" script to it, double-click to assign a script (the "CheckTriggeredLoads.asm" script is in the "Basic\System\ folder"):

2020-04-14-09-48-52-Project-Settings.png
 

twin paradox

New member
That was it! Thank you so much! It looks like I can also use this script to keep collectible tiles from returning after a screen has been triggered (Bonus!)
 
Top Bottom