1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Having a hard time with string_replace?

Discussion in 'Programming' started by KC Frye, Jul 18, 2019.

  1. KC Frye

    KC Frye Member

    Apr 15, 2019
    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:

    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:

    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:

    where "PlayerName" is a global variable set earlier to the player's name. For example, PlayerName = "Susie".

    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?
  2. chamaeleon

    chamaeleon Member

    Jun 21, 2016
    string_replace() does not modify the original string, it returns a new string as the result. Since you don't store that result anywhere, or otherwise make use of it in order to display it, your call to the function is effectively not doing anything for you.
  3. HeWhoShallNotBeNamed

    HeWhoShallNotBeNamed Member

    Nov 9, 2018
    If you have the player's name set to a variable, you can do this:

    playername = whatever the player sets their name as.
    myDialogue[0,0] = string(playername) + ", over here!"

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice