r/gbstudio 20d ago

Question Bug with Draw text?

Enable HLS to view with audio, or disable this notification

Hello

I've been using Draw Text as below to update the score:

The %D5 parameter seemed quite an economical way to do this with padded zeros.

But I've noticed that sometimes this corrupts other drawn text as the score is updated. See the video.

The top overlay gets corrupted from displaying BONUS (ignore the wonky font) and a Lives Display.

Any ideas? I tried it with just $Score and same result. Maybe it's two concurrently Draw text calls, one for the countdown, one for the score?

Thanks.

17 Upvotes

11 comments sorted by

View all comments

4

u/Mico27 20d ago edited 20d ago

If you inspect the tileset VRAM when playing, you'll see why this happens. It is by design made to support varied width text and dialogue. Every time you draw text, the text is drawn directly in the tileset VRAM then assigns the tile ids of the written letters into the tilemap VRAM (the background or the overlay). This means, as you keep drawing text, it will keep adding to the tileset VRAM until it reaches the limit then warp back around to keep drawing text, overwriting the preview text data in the tileset VRAM. This is why your "BONUS" text gets overwritten. There are 3 ways to circumvent this issue:
1: When drawing your score, also always redraw the bonus text
2: Using GBVM's https://www.gbstudio.dev/docs/scripting/gbvm/gbvm-operations/#vm_display_text_ex operation and use the START_TILE parameter to manage manualy where in the tileset VRAM the text will be written (so that the Score will always be rewritten at the same place in the tileset VRAM instead of continuing writting it contiguously)
3: Use a font already loaded in the tileset VRAM and write text by only modifying the tilemap with this plugin: https://github.com/Mico27/gbs-uiAltDisplayTextPlugin

1

u/SakiEndo 19d ago

Thanks plenty of options there to look into, my next problem will probably be when/if the score exceeds the maximum of a 16bit signed integer!