Creating certain things dynamically

Started by Kara Jo Kalinowski, Sat 08/03/2025 19:35:30

Previous topic - Next topic

Kara Jo Kalinowski

I'm wondering for certain types of things if they are possible to create using script instead of in the editor. Both in the current 3.6 version, and in the current 4.0 version.

Things like

Objects
Hotspots
Characters
GUI controls (i.e. buttons)

I asked about this when working on my Kyrandia GUI ages ago, but forget what the actual solution was that was recommended to me. Essentially my best solution at the time was to create a bunch of dummy characters and instantiate them from room to room as needed (easier than dummy objects because objects are room-specific so I would need to create dummy objects in each room.) For that kyrandia GUI, I was looking at specifically being able to drop off inventory items into any walkable area location. so my idea then was to pick an unused character, change the sprite, room number, x, y to the proper place. I'd still like to make the kyrandia GUI at some point, but it's not my current problem.

Now the thing I'm considering is a visual novel style GUI where it would display the text like a typewriter. It's not easy to calculate the width of a word unless your characters are fixed-width so I'm considering the same type of thing, making a bunch of dummy objects in the editor and instantiating each letter as necessary, but that's super tedious. So is there a way to create a new button on the fly? (Also, am I right to think that the only GUI elements that can have images are buttons?) I essentially did the same thing with my MAGSMan hangman game, though that one is limited to words 22 length.

Crimson Wizard

#1
The only on-screen object that may be created dynamically in AGS is still: Overlays.
Everything else would require a pool of reusable objects.

Overlays let to implement any kind of custom visible object, but they are very simple on their own, and would likely require to also have your data in script that defines them, and some extra script to handle interactions.

They might be used for droppable items. Previously one would use Characters, since these are unlimited and you can create as many as there are items in game, so long as that's classic adventure game and not e.g. RPG with thousands of possible items. But since they got improved in 3.6.0 Overlays are viable alternative, except they would require extra scripting.



About typewriter effect, I am puzzled about why do you consider a necessity of multiple objects for that. Normally this is done without any objects, just using a Label or DrawingSurface. It's also trivial to calculate width of text, AGS has a GetTextWidth and GetTextHeight functions that do that for you.
There are at least 3 script modules posted here on forums that support typewriter effect today. For instance, here's mine, which I created based on my Visual Novel experiment years ago: https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-typedtext-0-7-0/
But it's not super hard to write your own (I've seen people just writing a simple script for that when they needed this effect).
If you'd like to have letters as sprites, not relying on standard fonts, that's not a problem either, it's simply going to be a loop over characters in a string to know its size. There's a classic SpriteFont plugin that lets to have font made of sprites, substituting any font in game. But it's also possible to write a script that does the same with dynamic sprites and drawing on a surface. For instance, I made one for my older game Last & Furious. The code may be found in the game's repository:
https://github.com/ivan-mogilko/ags-lastfurious/blob/master/Last'n'Furious/SpriteFont.ash
https://github.com/ivan-mogilko/ags-lastfurious/blob/master/Last'n'Furious/SpriteFont.asc

Of course if it's absolutely necessary to use separate objects for displaying separate letters, then overlays may be useful here as well.
There's a module that makes use of them for extra effects, such as drawing each piece of text in its own way:
https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-fancy-0-1-0/

Kara Jo Kalinowski

#2
Quote from: Crimson Wizard on Sat 08/03/2025 22:22:46The only on-screen object that may be created dynamically in AGS is still: Overlays.
Everything else would require a pool of reusable objects.

Overlays let to implement any kind of custom visible object, but they are very simple on their own, and would likely require to also have your data in script that defines them, and some extra script to handle interactions.

They might be used for droppable items. Previously one would use Characters, since these are unlimited and you can create as many as there are items in game, so long as that's classic adventure game and not e.g. RPG with thousands of possible items. But since they got improved in 3.6.0 Overlays are viable alternative, except they would require extra scripting.



About typewriter effect, I am puzzled about why do you consider a necessity of multiple objects for that. Normally this is done without any objects, just using a Label or DrawingSurface. It's also trivial to calculate width of text, AGS has a GetTextWidth and GetTextHeight functions that do that for you.
There are at least 3 script modules posted here on forums that support typewriter effect today. For instance, here's mine, which I created based on my Visual Novel experiment years ago: https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-typedtext-0-7-0/
But it's not super hard to write your own (I've seen people just writing a simple script for that when they needed this effect).
If you'd like to have letters as sprites, not relying on standard fonts, that's not a problem either, it's simply going to be a loop over characters in a string to know its size. There's a classic SpriteFont plugin that lets to have font made of sprites, substituting any font in game. But it's also possible to write a script that does the same with dynamic sprites and drawing on a surface. For instance, I made one for my older game Last & Furious. The code may be found in the game's repository:
https://github.com/ivan-mogilko/ags-lastfurious/blob/master/Last'n'Furious/SpriteFont.ash
https://github.com/ivan-mogilko/ags-lastfurious/blob/master/Last'n'Furious/SpriteFont.asc

Of course if it's absolutely necessary to use separate objects for displaying separate letters, then overlays may be useful here as well.
There's a module that makes use of them for extra effects, such as drawing each piece of text in its own way:
https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-fancy-0-1-0/

Thank you for all of the information. I was not aware of GetTextHeight and GetTextWidth (sometimes navigating the help file leaves me unsure where to look). So if I am sticking with standard text functions, it should suit my needs fine. But if I want a fancier looking font I might use the sprite thing still.

SMF spam blocked by CleanTalk