• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2 String resourse


Is there a way to store strings as a resourse in game maker so you can just pull them like you do with sprites?
so how you have
we culd have

usually how i do this is i have a script with a switch in it where i store the texts.


Forum Staff
There are no text resources, but there are variables and functions that return strings. You could also store it in text files and read from them, but that loops back to the first sentence.
If all you want is to be able to refer to them through identifiers then you can go a couple ways.

1st way is to declare them as macros, but thing only works if they are constant strings at compile time
#macro txt_hello "Hello World"
2nd way is to declare them as global variables, which allows you to dynamically generate or read the strings from a file (e.g.) but you need to use the global. prefix
global.txt_hello = "Hello World"
You could combine both to have a macro point to a global variable as a way to shorten then name, but that means more setup effort for each string.

You then have even more possibilities like storing everything in a map and indexing it by the "identifier" of the string, using enums to index into a global array of the strings, etc. Just pick what fits better for your purpose