How to set sprite_index to a string?

Pafbar

Member
Hello!

(scroll down to see the crux of the issue)

I'm making a game with RPG-style dialogue, where the different characters you talk to have different poses when they talk to you based on their emotion. The system has global variables that determine which characters are on the left and right sides of the dialogue box, and the emotion of each character. I'm trying to make it so that when setting the sprites for these two sides of the box, I can just extract the values of these global variables and set the character's sprite index from the string. For example:

(in text controlling object)
global.Lemote = "happy"
global.Lcharacter = "fred"

[This script controls the left-side talking object, called obj_Ltalk. I have a sprite called happy_fred. This is in the create event]
sprite_index = string(global.Lemote)+"_"+ string(global.Lcharacter);

(crux of issue starts here)
My trouble is that the string tries to convert into an integer, so whenever I activate the text box it displays the error message:

unable to convert string "happy_fred" to integer
at gml_Object_obj_Ltalk_Create_0 (line 5) - sprite_index = string(global.Lcharacter)+"_"+string(global.Lemote);

So what should I do to make it recognize the string?
Thanks to anyone who responds!
 
In place of sprite_index? I've tried that but maybe I did it incorrectly.
Like this:
Code:
sprite_index = asset_get_index(string(global.Lemote)+"_"+ string(global.Lcharacter));
It helps to read the manual for any commands that you do not understand the usage of, as there are example in there for each one that will definitely help you.
 

Pafbar

Member
Like this:
Code:
sprite_index = asset_get_index(string(global.Lemote)+"_"+ string(global.Lcharacter));
It helps to read the manual for any commands that you do not understand the usage of, as there are example in there for each one that will definitely help you.
Ah. Thank you, that worked!
 
Top