• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM How to remove a # from a variable storing a players name

Okay, I have a game and the players name is stored inside a variable. But when their name has the # sign as any part of their name such as Sean#90 or Punk#ssB#tch.. then printing that variable name inside gamemaker causes the # to create an ENTER and it draws the Sean then [enter] and 90 on the next line -or- it would draw Punk then ss then tch on the next two lines.

Is there anyway to not make the draw command see the # as an "enter" or is there an easy loop or command to remove all # characters from a name variable?

Thanks!
 

Evanski

Raccoon Lord
Forum Staff
Moderator
GML:
string_replace(name,"#","");
could also replace # with /# which gml will see as just a # as text not a new line
 
awesome, thanks! ...But when I use that command.. Gamemaker is still entering everything after the # that we deleted on the next line.. which I don't want. How would I resolve this?
 
Last edited:

Roderick

Member
awesome, thanks! ...But when I use that command.. Gamemaker is still entering everything after the # that we deleted on the next line.. which I don't want. How would I resolve this?
string_replace() doesn't change the string that you feed it; it returns the modified string. You need to use name = string_replace(name, "#", "")

Also, I think string_replace only replaces the first occurrence, not all. You may need to create a loop that checks if there's a # and keeps running the command until they're all gone.
 
Last edited:

Evanski

Raccoon Lord
Forum Staff
Moderator
string_replace() doesn't change the string that you feed it; it returns the modified string. You need to use name = string_replace(name, "#", "")

Also, I think string_replace only replaces the first occurrence, not all. You may need to create a loop that checks if there's a # and keeps running the command until they're all gone.
String = string_replace_all(string,"#","");
 
Top