chrismaltby / gb-studio

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system
https://www.gbstudio.dev
MIT License
8.54k stars 470 forks source link

VM_REPLACE_TITLE_XY reading global variable index instead of value #1384

Open outerb opened 6 months ago

outerb commented 6 months ago

Describe the bug I am attempting use the VM_REPLACE_TITLE_XY method to replace a tile who's coordinates I provide via global variables. The VM_REPLACE_TITLE_XY appears to be using the index of the global variables instead of their assigned value.

To Reproduce Steps to reproduce the behavior:

  1. Create a logo scene called tilescene. This will be used to swap tiles.
  2. Create an empty script.
  3. Set two global variables. In my case, I set two variables based on the Player's position and added +1 to the X value. These variables are called VAR_CURSORX_1 and VAR_CURSORY_0.
  4. Add following GBVM Script:

VM_PUSH_CONST 3 VM_REPLACE_TILE_XY VAR_CURSORX_1, VAR_CURSORY_0 ___bank_bg_tilescene_tileset, _bg_tilescene_tileset, .ARG0 VM_POP 1

  1. Call the script OnInt.
  2. Instead of updating the title at the position I intended, the script updates the tile at position 4,5. I believe these are the index values of my two variables. (I included a display action in my screenshot below to show this).

Expected behavior I was hoping the script would update the tile at the position I provided, and not the use the index values of the variables.

Screenshots image

Platform (please complete the following information):

Additional context Apologies if this is user error, but I can't think of another way to get VM_REPLACE_TITLE_XY to read the value of the variables instead of their index.

pau-tomas commented 6 months ago

VM_REPLACE_TILE_XY only accepts values as the coordinates and not variables. To pass variables as the coordinates use VM_GET_TILE first and then VM_REPLACE_TILE.

outerb commented 6 months ago

Oh awesome I’ll give that a try thanks!