[4.5.9] Adding Monster Bits back in

JamesNES

Well-known member
If you've seen the "Monster Bits" panel in the monster setup window you've probably wondered what to do with them or how to use them. They can work as another set of monster flags, but they're not included in your game by default. NES Maker exports them when you compile but you have to bring them into your game yourself.

1652740047521.png


Bringing them in is straightforward, then to use them you have two choices. You can either create an object variable for them, which will use up your object RAM, or you can just have them in a bank somewhere and look them up by object type every time, which won't take up RAM but then you won't be able to alter the bits, they'll be fixed to what object type they're for.


Importing them without using Object RAM

First you need to get the monster bits into your project by importing them. You can do this in two places, depending on how you want to use them. If you're not going to use object RAM, it's easiest to put them into the static bank so you don't need to switch in order to look them up. It's 90 bytes so it's not a huge cost.

At the bottom of LoadAllSubroutines add:


Code:
MonsterBits:
   .include "ScreenData\ObjectData\MonsterBits.dat"

Now when you want to look at an object's monster bits, assuming the object ID is in x, you can just do:

Code:
  LDY Object_type,x
  LDA MonsterBits,y

And then check with AND and whatnot. All done for this method.


Importing them and using Object RAM

For this method, you need to add a monster bits variable in your object variable settings.

1652741107491.png


Since we only need to reference the imported data during object creation now, we can put these in bank 1C with the rest of the monster data.

So at the bottom of Bank1C.asm add:

Code:
MonsterBits:
   .include "ScreenData\ObjectData\MonsterBits.dat"

Now to load it into RAM when an object is created. This is handled in doHandleObjects (filename is different between modules):

1652741806027.png

Around line 70ish you should see something like:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Here, we create a new object.  It will exist upon the next frame.
                    .include SCR_CREATE_STATE
                   
                    JSR doHandleCreateState
                    SwitchBank #$1C
                        LDY Object_type,x
                        LDA ObjectFlags,y
                        STA Object_flags,x

                    ReturnBank
                   
                    JMP doObjectIsInactive
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

So during that bank switch we just need to add loading the bits in:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Here, we create a new object.  It will exist upon the next frame.
                    .include SCR_CREATE_STATE
                   
                    JSR doHandleCreateState
                    SwitchBank #$1C
                        LDY Object_type,x
                        LDA ObjectFlags,y
                        STA Object_flags,x
                        LDA MonsterBits,y
                        STA Monster_bits,x
                    ReturnBank
                   
                    JMP doObjectIsInactive
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Now objects will have their monster bits loaded in as a variable so you can change them during gameplay using LDA Monster_bits,x and so forth.
 
Last edited:

Bucket Mouse

Active member
Good work. I think I'd prefer the static version; I don't see a point in taking up RAM space with something that could just be a variable.
 

JamesNES

Well-known member
I think you might be misunderstanding, it's not a variable if it's not using RAM. Putting it in the static bank for the first method just makes it easier to access the (fixed) values from the monster editor.

That said, I didn't put them in RAM myself either. By the time I noticed monster bits were actually being exported I'd already come up with a bunch of other flag variables for my game!
 

Jonny

Well-known member
I went with the second method. It seems the most versitile way to fiddle with your monsters bits.
 

drexegar

Member
Oh wow I was going to start on getting the monster bits working this week and this post is here! Thanks for your hard work!!
 

tbizzle

Well-known member
Wow, so easy! I needed to be able to add more to my monsters too! Thank you 007 James Nes!
 
Top Bottom