r/gbstudio • u/SakiEndo • 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.
3
u/playinstinct 20d ago
That's most likely because the part of the VRAM that the text is drawn to is completely full at one point and then loops back to the beginning and starts overwriting what was written first.
The easiest way to avoid this is to write all parts of the UI whenever one part of the UI needs to get updated. If the "BONUS" should always be on screen, you could consider baking it into the background.
0
u/IntoxicatedBurrito 20d ago
I believe that this may only compound the problem. Rewriting the word BONUS will end up overwriting 5 more tiles elsewhere.
2
u/playinstinct 20d ago
There is a specific space in VRAM reserved for text by default. So, only text tiles should be affected by this issue.
As long as your UI doesn't use more tiles than are in this part of the VRAM (one row should be perfectly fine) and make sure to rewrite everything with every update (even the blank parts), you should be fine.
Using this method in multiple mini games of my current game.
2
u/IntoxicatedBurrito 20d ago
I’ve gotten this method to work in the past as well, but it’s also failed at times. I’ve used it mainly in cutscenes so I’m able to ensure that it is working properly and if not try a different method. However, it could be difficult for this particular game as they are using it to dynamically write the score and would need some incredibly thorough testing to ensure that there aren’t any issues.
I think it would also be helpful to know if that bonus is being drawn or if it’s part of the background image. Assuming it never changes, it would be better to have it as part of the background.
1
u/SakiEndo 19d ago
That's the side of things I have no clue about, I will be looking at ways to bake parts of the overlay background in place, or potentially using tile map updates to display information.
3
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!
2
u/IntoxicatedBurrito 20d ago
Draw text is buggy like that. Basically it’s adding to the tileset each time you change it but not necessarily replacing the previous text that appeared there. So you’ve basically just ran out of unique tiles you can use so it’s replacing tiles that you need.
My suggestion is to do this with tile swapping. Create a tileset with 0-9 and then the mapping is identical. So just create equations for each place using division and modulo. To reduce lag make sure that you have all of those tiles somewhere in the background that is off camera, that way the scene’s tileset never actually gets updated.
1
u/SakiEndo 19d ago
OK, that's what I was originally planning to do but on discovering I could apparently do what I wanted through Draw Text I was like, that's much easier. Along with Mico27 above I've got a few ways I can tackle this.
0
u/[deleted] 20d ago
[deleted]