459 ADV - Problem when calling CreateObject Macro from tile collision

My issue is that when I use CreateObject within tile collision scripts no matter what I set X and Y values to the new object always appears at the collision point.
I dug around the forums and couldn't find anything. Ideally I would like to create an object elsewhere in the room without having to pass along a flag. Any advice?
 

SciNEStist

Well-known member
I had astruggled with that myself, and in the end I decided on a workaround.

1 : I created 3 user variables :
effectcount, effectX, and effectY

2: when i want to spawn something at a certain spot, set effectX and effectY to the x and y coords I want it, then the effectcount variable to 1

3: in another script elsewhere that is run every frame (timer, physics, spritepredraw, etc) I check for effectcount to see if its 0, if not: spawn the object I want and set effectcount back to 0.

Code:
LDA effectCount
CMP #$00
BNE +
   CreateObject effectX, effectY, #YOUROBJECT, #$00, currentNametable
   LDA #$00
   STA effectCount
+

what this does is move the createobject stuff out of the tile script, where it can run normally.
 

dale_coop

Moderator
Staff member
My issue is that when I use CreateObject within tile collision scripts no matter what I set X and Y values to the new object always appears at the collision point.
I dug around the forums and couldn't find anything. Ideally I would like to create an object elsewhere in the room without having to pass along a flag. Any advice?
Make sure to use:
Code:
TXA
PHA
before your "CreateObject" line

And
Code:
PLA
TAX
just after.

Should look something like :
Code:
TXA
PHA

CreateObject tempA, tempB, <yourObjectID>, #$00

PLA
TAX
 
@SciNEStist, thanks for the reply, that's not a terrible method and is kind of what I have been doing up to this point.
Then I started fumbling with trying to make a push block.
I pictured hitting a "push" tile with a the melee weapon, the tile turns nul, creates a sprite in its place the sprites slides over 16 pixels destroys itself and spawns a new push block.
It will be complicated and I am not sure I can even pull it off but my first obstacle was that I could not get the sprite to appear anywhere other than directly at the collision, and this method was not going to work for my application.

@dale_coop, thank you again sir. That worked like a charm.
But I am baffled as to why simply backing up the X register is the fix. Do you have any insight?
 

dale_coop

Moderator
Staff member
@dale_coop, thank you again sir. That worked like a charm.
But I am baffled as to why simply backing up the X register is the fix. Do you have any insight?
When tile collision is executing, the current player object I loaded in X, right?
But the CreateObject macro creates a new object and loads that object in X.
When the tile collision ends, the player should be in the X registry (for the handle object to continue its loop...)
So... each time you use a creatobject macro you should make sure to restore the X registry right after.
 

Parkfun

New member
Thank you for that fix! That is one issue I was working through as well.

I've been working on a warp tile that warps the player on the same screen. I'm not sure what I'm doing wrong, but I'm very new to assembly language. It works, but the screen refreshes in order for it to move the player. How can I get the player to warp on the same screen without the refresh?

;Player warps to 15, 85 on the same screen
LDA #15 ;Sets X coordinate for the Player on the screen
STA newX
LDA #85 ;Sets Y coordinate for the Player on the screen
STA newY

LDA gameHandler
ORA #%10000000
STA gameHandler
 
Thank you for that fix! That is one issue I was working through as well.

I've been working on a warp tile that warps the player on the same screen. I'm not sure what I'm doing wrong, but I'm very new to assembly language. It works, but the screen refreshes in order for it to move the player. How can I get the player to warp on the same screen without the refresh?

;Player warps to 15, 85 on the same screen
LDA #15 ;Sets X coordinate for the Player on the screen
STA newX
LDA #85 ;Sets Y coordinate for the Player on the screen
STA newY

LDA gameHandler
ORA #%10000000
STA gameHandler
I have not used it but there is an UpdatePosition Macro.
Looks like it just takes an object and puts it somewhere else.
 

Parkfun

New member
Thanks SirBunnyMcNuggets, I've tried the UpdatePosition Macro as well and can't seem to get it to work like the code above. I actually can't get it to work at all using that macro. I also searched UpdatePosition in the entire NESMaker folder structure and couldn't find it being used anywhere in code.
 
Yeah, I just tried it too. If you follow you logic the routine is pretty straight forward.
Maybe it was created for another module.
I tried to figure out some other way to "teleport" to a different location on the same screen.
I figured out that within the tile script you can DestroyObject on the player and create another Player object anywhere you want.
I just doesn't move. I'm guessing because the game does not recognize it as the player object.
 

Parkfun

New member
Haha, I tried the DestroyObject / CreateObject thing as well. It put my player where I wanted him with no flicker or anything, but I also couldn't get the player to move after it repositioned it. I feel like we're both pretty close. I think I'll repost my question in the Help me section. I didn't realize there was a place for general code questions until after I posted before. Thanks for trying with this!
 

JamesNES

Well-known member
Just use xHold_hi and yHold_hi - at the end of the physics script and everything in that it sets an object's position to these.

Code:
LDA #$30
STA xHold_hi
LDA #$30
STA yHold_hi

Just a matter of finding the magic variable to change.
 

Parkfun

New member
Just use xHold_hi and yHold_hi - at the end of the physics script and everything in that it sets an object's position to these.

Code:
LDA #$30
STA xHold_hi
LDA #$30
STA yHold_hi

Just a matter of finding the magic variable to change.
Thank you! Thank you! Thank you! You're right, I just need to research the physics scripts when I'm stuck on something to figure out what variables do what. This worked perfectly!!!
 
Top Bottom