GMS 2 String resourse

zendraw

Member
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
draw_sprite(spr_player);
we culd have
draw_text(txt_bio);

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

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 

zendraw

Member
yeah i actually remembered that a thing like arrays exist... and you can make anything a resourse pretty much.
 
D

Deleted member 45063

Guest
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
GML:
#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
Code:
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
 
Top