Variables and monster blocks

baardbi

Well-known member
I have a HUD variable called mySwitches. Every time I flip a switch in the game (actually it's a pickup that is collected) the variable increases. These switches are located in three separate rooms. When the variable mySwitches reaches 3 I want another room to be triggered (day triggered) as well as having the monster blocks in that room removed. Any ideas how I can achieve this?
 

dale_coop

Moderator
Staff member
I would see a script assigned to your pickup (powerUp XX) like that:

Code:
	;; increments the Switches var
	INC mySwitches

	LDA mySwitches
	CMP #$03
	BCC +
		;; trigger the screen where the locked door is :
		TriggerScreen #12		;;<-- HERE, the value is the screen type value of the other room to trigger
		
		; PlaySound #SFX_UNLOCK_ROOM
		
		;; set back the mySwitches to 0
		LDA #$00
		STA mySwitches
		
		JMP ++
	+	
	
	; PlaySound #SFX_GET_SWITCH
	
	++

	;; updates the HUD :
	LDA mySwitches
	STA hudElementTilesToLoad		
	UpdateHud HUD_mySwitches
	
	;; in every cases, we trigger the current screen, to not have again that switch on that screen:
	TriggerScreen screenType

Make sure your 4 rooms have a unique screen-type value (in the screen "Infos").
Also modify the script above (the"HERE" comment) with the screen type value of the 4th room, you want to trigger when you collect all the switches.
 

baardbi

Well-known member
This is awesome Dale! It works perfectly. Thank you very much :) Now I just have to get the monster blocks to disappear as well.
 

dale_coop

Moderator
Staff member
If there are no more monster in your (triggered) room, there should be no more monster lock tile.
If those tile remain, maybe you have incorrect user consants (COL_MONSTER_LOCK? TILE_MONSTER_LOCK?...)
Which module are you using?
 

baardbi

Well-known member
I have to admit I'm a little bit confused. I'm not sure what the constant COL_MONSTER_LOCK does...

Here are my constants:

colmonlock.png


I tried to assign the MonsterBarrier.asm script to the monster block tile, but I get an error "Label already defined" (skipSolidRead) when I compile.

monbarrier.png


Here is the code in the MonsterBarrier.asm file:

Code:
	CPX player1_object
	BEQ skipSolidRead
	LDA Object_flags,x  ;; check the type of object
	AND #%00010100 		;; is it a player/monster weapon ? 
	BNE skipSolidRead	;; it IS, we skip	
	LDA #TILE_SOLID
	STA tile_solidity
skipSolidRead:	
	;; if you want it solid, declare it at the end

PS! I'm using the simple platformer module.
 

dale_coop

Moderator
Staff member
The "COL_MONSTER_LOCK" constant value should match with your Monster Lock tile type (if it's "14 - Monster Locks", you're good).

The "TILE_MONSTER_LOCK" constant value should be the index of the tile you use as your Monster Lock tile.
The "TILE_MONSTER_LOCK_OFF" constant value should be the index of the tile you use as when the Monster Lock tile is removed (replaced).

To find the index value of a tile, you can look at the tile infos here :

2019-01-16-11-22-53-NES-MAKER-4-1-1-Version-0x158-Adventure-Test-MST.png

Here, in this example it's a tileID #$46 (in hexa), it means 70 in numeric.

You can also check directly in your tileset, counting from 0 to 255 (from top to bottom, left to right) :
2019-01-16-11-24-52-NES-MAKER-4-1-1-Version-0x158-Adventure-Test-MST.png
 

baardbi

Well-known member
It looks like everything is correct here, but there is one thing that I think might be the problem. I'm not sure what script I should assign to the Monster Lock tile. I was confused at first, and tried to assign the Monster Barrier.... :oops: I know now that was a mistake :) Is there a script for monster locks, or do I have to make it myself?
 

baardbi

Well-known member
It works perfectly now. I just had to uncomment three lines in Handle_CheckForMonsters_DC.asm:

Code:
	LDA showingNametable
	STA temp
	ChangeAllTilesDirect #COL_MONSTER_LOCK, #$00, #TILE_MONSTER_LOCK_OFF, temp

I was completely stuck before you pointed out a few things in this post. Thanks for helping me in the right direction so I could solve this problem :)
 
Top Bottom