key issue

I don't recall this happening before, but I didn't extensively test and I haven't played with nesmaker in a while

I have a locked door (#1) that doesn't open until you get key 1.

After that, I have locked door #2, that doesn't open until you get key 2.

but then, I have locked door 3, that opens without getting key 3. No idea why. Any thoughts? thanks!
 

dale_coop

Moderator
Staff member
Are you sure your door 3 is not on a already triggered screen (make sure its screen-type number is different then other screens)...?
 

dale_coop

Moderator
Staff member
Or maybe your myKeys variable has been increased by some code? (sometimes the add score can corrupt the myKeys variable... if the score of your HUD is not displayed as intended by the code, it means a number 8 digit HUD element)
 
Thanks! I'll double check about the triggered screen issue. I bet that is it. No reason for the myKeys variable to be messed with but I'll double check that as well :)
 
Hmm, nope looks like it is a unique screen number.

Either by coincidence or design, all screens with keys have a unique type, and all screens with locks have a unique type.

But, I just started the game on the screen that has the issue, and the door is locked. If I go and get key 3, I can then unlock it.

When I start the game on the screen where I get key #2, the issue emerges and I can open door 2 and 3 without getting key 3.

So I guess the issue is there somewhere. I just don't understand because the screens have unique types.

I've attached a pic of the overwork screen.

keyissue.png
 

dale_coop

Moderator
Staff member
You know that there is no link between key and doors number right.
It's just if your myKeys variable has a value different than 0, you can open a door (any door). When you unlock a door, your myKeys variable decreases its value.

So, for your door 3... I think something makes your myKeys increases somehow, somewhere before you get to that door. Maybe something executed a increase of your myScore variable (as I wrote, it could add increase your keys because both variables are close in memory).
Maybe you have a monster just before that door 3 (or the screen before) and you killed him? Or a collectable tile?
 
Right, I understand that it just counts keys and if key>= 1, then the door can open. I just didn't know why it thinks I have a key when it should be at zero at that point in the game.

i remember playing around with collectable tiles. I have health pickups too. I'll dig around in that stuff a bit more. thanks again for your help! :)
 

dale_coop

Moderator
Staff member
So it might be your collectable script
By default that script increases the myScore variable. And is made to work with a Score displayed as a number HUD element 8 digits.
If it's not the case of your game, your keys variable could be corrupted when you collect a Collectable tile.

How is your score HUD variable? do you have one (displayed on your HUD)?
 
I don't have a score or anything, or at least I never messed around with any of that stuff. My HUD just has a life bar.

I used the collectable script to make a health collectable at some point. And then I got the key script. Will dig around a bit when I get time :) I bet you're right though and has something to do with this.
 

dale_coop

Moderator
Staff member
If you don't have the score on your HUD.
So you need to comment out all the myScore increasing code that are in the scripts.. that cause the corruption of your keys variable.
I will show you... Could you share, your Collectable script?
 
Sure thanks!

Code:
;; COLLECTABLE - this tile requires 
;; HUD to be active and for myScore variable to be drawn.
;; To use this without this feature, comment out lines marked below.

;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
	LDA myHealth
	CLC
	ADC #$01
	CMP #$06		;; <--- HERE the max health limit you can NOT reach (means if your max health is 8, here is 9)
	BCS skipGettingHealth
	
	TXA
	STA tempx
	;;;you may want to test against a MAX HEALTH.
	;;; this could be a static number in which case you could just check against that number
	;;; or it could be a variable you set up which may change as you go through the game.
	inc myHealth
	inc myHealth
	inc myHealth
	LDA myHealth
	
	LDX player1_object
	STA Object_health,x

	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		; LDA DrawHudBytes
		; ORA #HUD_myHealth
		; STA DrawHudBytes
	UpdateHud HUD_myHealth
	LDX tempx
	
skipGettingHealth:
	;PlaySound #SFX_INCREASE_HEALTH

	ChangeTileAtCollision #$00, #$00
 
Oh, and here is the key script

I see now that it says: ;;; TO USE WITHOUT HUD, COMMENT OUT THIS BLOCK
;;; It may result in anomalies if two tiles
;;; register collision simultaneously without
;;; this block.
LDA #$01
STA tileCollisionFlag
ChangeTileAtCollision #$00, #$00

So if I comment that out it should behave, or is there something else too that I need to do?


Code:
;; COLLECTABLE - this tile requires 
;; HUD to be active and for myScore variable to be drawn.
;; To use this without this feature, comment out lines marked below.
	CPX player1_object
	BEQ isPlayerForCollectableKeys
	JMP ++
isPlayerForCollectableKeys:
	LDA tileCollisionFlag
	BEQ +
	JMP ++
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; TO USE WITHOUT HUD, COMMENT OUT THIS BLOCK
;;; It may result in anomalies if two tiles
;;; register collision simultaneously without
;;; this block.
	LDA #$01
	STA tileCollisionFlag
	ChangeTileAtCollision #$00, #$00
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	TXA
	STA tempx	
	AddValue #$02, myKeys, #$01, #$00
	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	;STA hudElementTilesToLoad
	;	LDA #$00
	;	STA hudElementTilesMax
		; LDA DrawHudBytes
		; ora #HUD_myKeys
		; STA DrawHudBytes
		
	UpdateHud HUD_myKeys
	
	LDX tempx
	PlaySound #SND_GET
	LDA #$00
	STA value
	STA value+1
	STA value+2
	STA value+3
	STA value+4
	STA value+5
	STA value+6
	STA value+7
	
	TriggerScreen screenType
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


++
 
Sorry for all the messages. Just wanted to add: I went back and removed all of the pickup/collectable scripts (health, and a random one I had implemented but not used in my game) and just replaced them with the null walkable tile script I still have the problem: I pick up 1 key, use it, but then I can still unlock another door.
 

dale_coop

Moderator
Staff member
I am lost... what you modified and what you removed...
Could you share a copy of your NESMaker? (with the rooms to test)
It will be easier for me to check directly and tell you how to fix ;)
 
I don't think I ever changed anything with the keys file. The health tile pickup I made up myself, likely with some help from you/the forum here. It was a long time ago :)

I'll be sure to do that thank you! I forget, what files do you need exactly to be zipped? In the past, if I recall, it has only been a subset of files right?
 

dale_coop

Moderator
Staff member
I'd need more specifically your project MST file, the "GameEngineData" and the "GraphicAssets" folders.
(and a easy way to reproduce the issue... without spending 15 min of gaming, farming ;)).
 
So my outbox and "sent" don't show anything, so I don't know what is happening there. Screw it I'll just share it here :)

https://filebin.net/9n8q9vfujcvq1ohp
 
Top Bottom