Making userScreenByte0-7 work! (Plus Bonus!)

Hey guys, got a quick code edit which will actually link those userScreenBytes on your Screen Info options!

Why is this useful?
Well, you can store a number in any of those 8 boxes, that is unique to the screen, and it will show up in a variable in game. This can give you some powerful customizability.
For example, I'm going to use it to determine what NPC text responses are available on that screen.

I did something similar in 4.1.5, and it was a key factor in how I got around the limits on tile types and monster AI scripts.
Another example: boss monsters in Nix all share the same script (AI script 15) but based on the screenType, it runs a different portion of the script.
The problem with using screenType is that it is mainly used to determine if the screen is triggered, so I had to carefully design each of those screens and account for if the screen is triggered.
Same with tile types. It was a bit of a headache. Moving on.

This will basically give you 8 new 'screen type' variables that are independent and you can use for whatever purpose you want, and mix and match.

All you need to do is 2 steps:

Step 1)
Add these user variables:
userScreenByte0
userScreenByte1
userScreenByte2
userScreenByte3
userScreenByte4
userScreenByte5
userScreenByte6
userScreenByte7

Step 2)
Open up your GameEngineData\Routines\BASE_4_5\Game\Subroutines\doLoadScreenData.asm and make these changes:
(WARNING: !!BACK UP YOUR ORIGINAL FILE!!)
go to line 167, you should see this:
Code:
;; 131 

	LDY #182
	LDA (collisionPointer),y
	STA ScreenFlags01

Just after that, add this code block:
Code:
;; Load the userScreenBytes
	;; userScreenByte0
	LDY #187
	LDA (collisionPointer),y
	STA userScreenByte0
	INY
	LDA (collisionPointer),y
	STA userScreenByte1
	INY
	LDA (collisionPointer),y
	STA userScreenByte2
	INY
	LDA (collisionPointer),y
	STA userScreenByte3
	INY
	LDA (collisionPointer),y
	STA userScreenByte4
	INY
	LDA (collisionPointer),y
	STA userScreenByte5
	INY
	LDA (collisionPointer),y
	STA userScreenByte6
	INY
	LDA (collisionPointer),y
	STA userScreenByte7

And your done! Now when you enter a number into one of the userScreenBytes on your screen info page, you can access it in code from the variables userScreenByte0 - userScreenByte7
Remember you can rename them in your project label settings if you want to remember what each does.

I hope this helps you out with your projects!



BONUS:
This is a small addition that can also give you access to the special tile types (Tile Type 14 subtype and Tile Type 15 subtype)
Make Tile 14 and 15 each have 8 subtypes!

Add 1 more user variable:
specialTileType

Add this small block right after 'STA userScreenByte7':
Code:
;; Load the special tile types (14 and 15)
	LDY #195
	LDA (collisionPointer),y
	STA specialTileType

Get those subtypes from code this way:
Tile 14 subtype:
Code:
LDA specialTileType
AND #%00000111
STA temp
Tile 15 subtype:
Code:
LDA specialTileType
AND #%00111000
STA temp
 
Just stumbled on this. I can totally imagine some of the possibilities of your approach. It's very, very clever. Thanks for the post!
 

TolerantX

Active member
Hey guys, got a quick code edit which will actually link those userScreenBytes on your Screen Info options!

Why is this useful?
Well, you can store a number in any of those 8 boxes, that is unique to the screen, and it will show up in a variable in game. This can give you some powerful customizability.
For example, I'm going to use it to determine what NPC text responses are available on that screen.

I did something similar in 4.1.5, and it was a key factor in how I got around the limits on tile types and monster AI scripts.
Another example: boss monsters in Nix all share the same script (AI script 15) but based on the screenType, it runs a different portion of the script.
The problem with using screenType is that it is mainly used to determine if the screen is triggered, so I had to carefully design each of those screens and account for if the screen is triggered.
Same with tile types. It was a bit of a headache. Moving on.

This will basically give you 8 new 'screen type' variables that are independent and you can use for whatever purpose you want, and mix and match.

All you need to do is 2 steps:

Step 1)
Add these user variables:
userScreenByte0
userScreenByte1
userScreenByte2
userScreenByte3
userScreenByte4
userScreenByte5
userScreenByte6
userScreenByte7

Step 2)
Open up your GameEngineData\Routines\BASE_4_5\Game\Subroutines\doLoadScreenData.asm and make these changes:
(WARNING: !!BACK UP YOUR ORIGINAL FILE!!)
go to line 167, you should see this:
Code:
;; 131

    LDY #182
    LDA (collisionPointer),y
    STA ScreenFlags01

Just after that, add this code block:
Code:
;; Load the userScreenBytes
    ;; userScreenByte0
    LDY #187
    LDA (collisionPointer),y
    STA userScreenByte0
    INY
    LDA (collisionPointer),y
    STA userScreenByte1
    INY
    LDA (collisionPointer),y
    STA userScreenByte2
    INY
    LDA (collisionPointer),y
    STA userScreenByte3
    INY
    LDA (collisionPointer),y
    STA userScreenByte4
    INY
    LDA (collisionPointer),y
    STA userScreenByte5
    INY
    LDA (collisionPointer),y
    STA userScreenByte6
    INY
    LDA (collisionPointer),y
    STA userScreenByte7

And your done! Now when you enter a number into one of the userScreenBytes on your screen info page, you can access it in code from the variables userScreenByte0 - userScreenByte7
Remember you can rename them in your project label settings if you want to remember what each does.

I hope this helps you out with your projects!



BONUS:
This is a small addition that can also give you access to the special tile types (Tile Type 14 subtype and Tile Type 15 subtype)
Make Tile 14 and 15 each have 8 subtypes!

Add 1 more user variable:
specialTileType

Add this small block right after 'STA userScreenByte7':
Code:
;; Load the special tile types (14 and 15)
    LDY #195
    LDA (collisionPointer),y
    STA specialTileType

Get those subtypes from code this way:
Tile 14 subtype:
Code:
LDA specialTileType
AND #%00000111
STA temp
Tile 15 subtype:
Code:
LDA specialTileType
AND #%00111000
STA temp
Thank you for all the help!
View: https://youtu.be/HVhr9AgcKkQ
 

Jonny

Well-known member
@chronicleroflegends could this be used for monster bits? when you load the register into Y and increase it, is that a specific place NM uses for that think (i.e userscreenbytes have to start at #187) ?
I haven't seen must covered with monster bits, just that they don't work out of the box.
 
Top Bottom