ChangeTileAtPosition Variable?

Before you ask, ChangeTileAtPosition.asm is a custom macro made by @JamesNES my problem is that it requires a dual variable
Ex:
ChangeTileAtPosition #$08, BothX&YVariables
How do I combine two variables into one?
I did look at the 6502 site sent by James, but yeah this should be a simple answer to provide I'm just personally stumped for many reasons. If you want to know it's a combination of vacation busyness & fast recovery from le funny brain thing I sent in my first saying hi to nesmaker. Thank you for listening!
Please clap... - quote from funni failure dude
 
give it up for day 4! day 4 of me still not getting it! haha! - some picky moron programmer that can teach another how to "push blocks" at least!
funnily enough, I can BOTH upload that tutorial on sat/sun as well as incorporate something I found rehearsing it
for this game of all things:

I AM STILL WANTING TO DO FIRE EMBLEM-ISH GAME: PROJECT HEXAGON FIRST!...
But yeah I can implement what I found by the end of the month in funni pong-like game.
for what other than simple pong?
You'll see, you'll all see! hahahaahahahahahaahahah!
 

dale_coop

Moderator
Staff member
Strange... I don't use ChangeTileAtCollision like that.
the first parameter is the graphic (tile id) that will replace... And the second parameter is the collision data.
for example if I use:
ChangeTileAtCollision #$01, #$00
The tile will be replaced by my tile 01 (from the current background tileset) and the collision data will become 00 null walkable.

if you want to replace a different tile that the one that is in collision with the player... you will need to modify the tileX and tileY variables just before calling ChangeTileAtCollision.
 
Strange... I don't use ChangeTileAtCollision like that.
the first parameter is the graphic (tile id) that will replace... And the second parameter is the collision data.
for example if I use:
ChangeTileAtCollision #$01, #$00
The tile will be replaced by my tile 01 (from the current background tileset) and the collision data will become 00 null walkable.

if you want to replace a different tile that the one that is in collision with the player... you will need to modify the tileX and tileY variables just before calling ChangeTileAtCollision.
Thanks for your help, this won't help though. I've tried ChangeTileAtCollision
In my game and it can only do one per postscreenload...
I need it to do multiple times per postscreenload (it's kinda hard to explain without showing and will tomorrow if asked) that's why I need to learn how to use ChangeTileAtPosition made by @JamesNES
 

Bucket Mouse

Active member
I know for a fact I've changed more than one tile using ChangeTileAtCollision. So I looked up what I did.
And you're right that the macro only works for one frame. So I used JSR doWaitFrame to go to the next frame, then reloaded the X and Y coordinates.

This is an example of how you would write it, not a cut-and-paste ready drop-in code:

LDA #$3C
STA temp1
LDA #$29
STA temp2
ChangeTileAtCollision t_number1, #$00
JSR doWaitFrame
LDA #$3C
STA temp1
LDA #$2A
STA temp2
ChangeTileAtCollision t_number2, #$00

Hope this helps! Now I could really use the secrets of Pong.
 

JamesNES

Well-known member
Alright so you need to do some basic bitwise stuff, this is important as hell to learn as you can do so much with it without having to make new variables and so forth.

The metatiles on the screen are from 0 to 15 across, and 0 to 14 down. So if you want to change the third metatile across, and the fourth down, ie (3,4), their values are #$30 and #$40.

How do you combine these into one byte? Say X, #$30, is in tempA, and Y, #$40, is in tempB.

Code:
LDA tempA  ;; #%00110000 at the moment
LSR  ;;shift all the bits right four times
LSR
LSR
LSR ;; so now it's #%00000011 because the bits have been moved right four times
ORA tempB ;; ORA merges two values, so any bits that were 0 in one variable but 1 in the other will be 1 now.
STA tempC

tempC now is #%01000011 ie #$43.

And you got your YX stored in tempC now.

This is a good way to save space for, in your case, saving tiles that have been changed. Instead of needing to save the X and the Y of a metatile in two bytes of RAM, you can save it as one, as metatiles don't need the bottom half of the byte. Because they're all divisible by 16, being 16x16 blocks.

As an aside, the reason ChangeTileAtCollision can only update one tile per frame is because it resets maxScrollOffsetCounter to #$00 every time it's called. If you change LDY #$00 at line 73 to just be LDY maxScrollOffsetCounter, it'll keep upping the amount it draws. But you have to balance it with how much time you have to draw tiles; by default it's set to update #$10 tiles (8x8 not metatiles) per frame, so if you're not careful it'll be easy to overrun and start blasting out garbage.

You can mess with that #$10 number in doUpdateScrollColumn.asm to see what works for your game. It depends on how much stuff you've jammed into your NMI.
 
@JamesNES starting to think I didn't Install ChangeTileAtPosition correctly, put in the code as you said in my case:
LDA UnitOneLocationX
LSR
LSR
LSR
LSR
ORA UnitOneLocationY
STA UnitOneLocation
ChangeTileAtPosition #$08, UnitOneLocation
but am getting an error:
Routines\BASE_4_5\Game\Subroutines\myPostScreenLoad.asm(10):ChangeTileAtPosition(7): Unknown Label
so funnily enough this is the error I got before so it really wasn't me the whole time I Guess?
here is the line of code (7) NESMAKER for some reason considers incorrect:
STA arg1_hold
even though the same script has this at line 5 with no error:
STA arg0_hold
so yeah... advice?
 
I know for a fact I've changed more than one tile using ChangeTileAtCollision. So I looked up what I did.
And you're right that the macro only works for one frame. So I used JSR doWaitFrame to go to the next frame, then reloaded the X and Y coordinates.

This is an example of how you would write it, not a cut-and-paste ready drop-in code:

LDA #$3C
STA temp1
LDA #$29
STA temp2
ChangeTileAtCollision t_number1, #$00
JSR doWaitFrame
LDA #$3C
STA temp1
LDA #$2A
STA temp2
ChangeTileAtCollision t_number2, #$00

Hope this helps! Now I could really use the secrets of Pong.
willing to try this but quick question: how did you use ChangeTileAtCollision outside of the tile script itself?
I just tried spawning objects in all at once then with the each compatabile empty tile it would swap on collision.
anyway did you do what I described? or was the script example put into the tile script...
if that's the case I need to consider listening to JamesNES's advice with his custom macro, but now that I tried that and it gave me the same error
either I need him to help me figure out what I did wrong or help me understand what I did wrong specifically installing his macro.
and trust me I'll post a funni pong tutorial it's going to be awhile from now though due to reasons I already shared on this site.
if you want want me to repeat the reasons again just ask me and i'll compile them into one giant thread. hope I can help you with the pong-like game at the latest:
December of this year! (Yes I can be that busy) earilest though if I have time will be End of my Birthmonth funnily enough August... so stay tuned!
 

Bucket Mouse

Active member
willing to try this but quick question: how did you use ChangeTileAtCollision outside of the tile script itself?
I just tried spawning objects in all at once then with the each compatabile empty tile it would swap on collision.
anyway did you do what I described? or was the script example put into the tile script...
I don't understand what you're saying. Here's how it's used in this case: you load the coordinates of X and Y for the tile you want to change in temp1 and temp2, because the macro uses those. Then you run the macro, then you skip a frame, then you do it again to change a different tile. If you chain these together, every tile you want to change will change when a sprite touches one tile.
 
I don't understand what you're saying. Here's how it's used in this case: you load the coordinates of X and Y for the tile you want to change in temp1 and temp2, because the macro uses those. Then you run the macro, then you skip a frame, then you do it again to change a different tile. If you chain these together, every tile you want to change will change when a sprite touches one tile.
I get that, but your code didn't use the macro I received from JamesNES (ChangeTileAtPosition) it used ChangeTileAtCollision which shouldn't work outside of a tile script but i'll try
 
Last edited:

Bucket Mouse

Active member
K... so if possible can you explain your advice better? For changetileatcollision?
Because I checked and funnily enough it sorta works now... it just won't change the tiles graphics right away until you interact with it
Yeah, a sprite needs to touch it for it to go off, since it's a tile script. If you wanted it to be triggered another way, you'd have to put it somewhere else and make the conditions for activation different, like a variable would have to be on.
 
Yeah, a sprite needs to touch it for it to go off, since it's a tile script. If you wanted it to be triggered another way, you'd have to put it somewhere else and make the conditions for activation different, like a variable would have to be on.
at the very least my current code changes the Tile Id, but not the graphics unfortunately:
View: https://youtu.be/hlkkl-YwJbM


again with either @JamesNES's Macro or the original one... I don't care which one solves this graphics glitch, I just would like it solved.
 

Bucket Mouse

Active member
With something like that, wouldn't you only need to change one tile at a time? My Mess Maker works that way. It changes whatever tile the cursor is under to what the player has selected.
 

Attachments

  • messmaker.zip
    21 KB · Views: 2
With something like that, wouldn't you only need to change one tile at a time? My Mess Maker works that way. It changes whatever tile the cursor is under to what the player has selected.
no that's just currently where my game is, it loads the tiles by changing them with an Invisible CreateObject that spawns and delete's itself just in time for the
tiles to change. funnily enough, as I showed in the video all units are actually in place... the problem is only the last "spawned" unit gets its tile graphics changed
which I just don't know why that is. might either need to fix the ChangeTileAtCollision Macro somehow, or again attempt to try @JamesNES's macro and figure out why it gives me an error every time I use it.
 
Okay! Good news! game's not Crashing anymore using changetileatposition
bad news! I still can't access changing the tile at position....

here is my code in postscreenload if anybody can help me...

LDA UnitOneLocationSpriteY
ASL
ASL
ASL
ASL
ORA UnitOneLocationSpriteX
STA myTemp
ChangeTileAtPosition #$08, myTemp
I Still need help, it's not changing the tile at the position I give it
 
Last edited:
Top Bottom