K
KC Frye
Guest
I'm trying to make a game where I can insert the player's name into the dialogue, but I can't get the string_replace function to work?
The dialogue of each character originates in either the Step or Create function of each character and will read as follows:
The text itself, once converted to the variable "myMessage" is drawn inside of the object "obj_dialogueBox" and reads as follows:
The problem is that I can't for the life of me, figure out where to put this code to make it work. Please help?
The dialogue of each character originates in either the Step or Create function of each character and will read as follows:
With "playername" being the substring I'm trying to replace. The character then runs a script in the step function called scr_dialogue which contains this code:myDialogue [0,0] = "playername, over here!"
DialogueSystemOn = true;
dialogueBox = instance_create_layer(camera_get_view_x(view_camera[0]) + 6, camera_get_view_y(view_camera[0]) + 335, "DialogueBox", obj_DialogueBox);
if messageGiver.hasExpression = true {
expressionBox = instance_create_layer(camera_get_view_x(view_camera[0]) + 64,camera_get_view_y(view_camera[0]) + 152, "DialogueBox", obj_ExpressionBox);
}
with (dialogueBox) {
maxLength = sprite_width - 36;
maxHeight = sprite_height - 24;
myMessage = messageGiver.myDialogue[index1,index2];
messageIndex = 0;
if (string_height_ext(myMessage, 28, maxLength) > maxHeight) {
textHeight = string_height_ext(messageGiver.myDialogue[index1, index2], 28, maxLength);
amount = (textHeight / (sprite_height - 24));;
startingAt = 0;
for (i = 0; i < amount; ++i) {
myMessage = string_copy(messageGiver.myDialogue[index1, index2], startingAt, (string_length(messageGiver.myDialogue [index1, index2]) / amount))
startingAt = string_length(myMessage[index1, index2]) * (i + 1);
}
}
else
myMessage[messageIndex] = messageGiver.myDialogue [index1, index2];
}
The text itself, once converted to the variable "myMessage" is drawn inside of the object "obj_dialogueBox" and reads as follows:
The code I am trying to use to replace "playername" with the actual name of the player is some variant of this code:draw_self();
draw_set_color(c_black);
draw_set_font(messageGiver.fnt);
draw_text_ext(bbox_left + 20, bbox_top + 18, myMessage[messageIndex], 28, maxLength);
where "PlayerName" is a global variable set earlier to the player's name. For example, PlayerName = "Susie".if (string_pos("playername", myMessage) != 0)
{
string_replace(myMessage, "playername", PlayerName)
}
The problem is that I can't for the life of me, figure out where to put this code to make it work. Please help?