• 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!

GameMaker (solved) string_replace is completely broken (im just an idiot)

Evanski

Raccoon Lord
Forum Staff
Moderator
Heres what I mean:
We have a string (our_password)

Code:
our_password = "2000000";
Okay now what we want is for 0 to become 1

So in a step event we put:
Code:
our_password = string_replace(our_password, 0, 1);
So because its in a step event it will replace all the 0's, dont worry about that just look what happens

When the code runs the string becomes this:
Code:
2`61111
Shouldn't it be:
Code:
2111111
 

chamaeleon

Member
Heres what I mean:
We have a string (our_password)

Code:
our_password = "2000000";
Okay now what we want is for 0 to become 1

So in a step event we put:
Code:
our_password = string_replace(our_password, 0, 1);
So because its in a step event it will replace all the 0's, dont worry about that just look what happens

When the code runs the string becomes this:
Code:
2`61111
Shouldn't it be:
Code:
2111111
You could try to actually pass strings as arguments instead of numbers..
 
D

Danei

Guest
I think you need to be replacing substrings with substrings and not integers. Try
Code:
our_password = string_replace(our_password,"0", "1");
 

samspade

Member
Heres what I mean:
We have a string (our_password)

Code:
our_password = "2000000";
Okay now what we want is for 0 to become 1

So in a step event we put:
Code:
our_password = string_replace(our_password, 0, 1);
So because its in a step event it will replace all the 0's, dont worry about that just look what happens

When the code runs the string becomes this:
Code:
2`61111
Shouldn't it be:
Code:
2111111
Just a quick review of the manual shows you what the problem is: https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/strings/string_replace.html
 
B

Bayesian

Guest
I was not able to reproduce using the exact code from the OP. It works as intended. Something else is wrong. Try clearing your cache(broom icon) and checking for other references to our_password

edit: Also you should be running this once with string_replace_all()

Code:
///Create
str = "2000000"
show_debug_message(str)
Code:
//Step
str = string_replace(str, 0, 1)

show_debug_message(str)
Code:
///Output
2000000
2100000
2110000
2111000
2111100
2111110
2111111
...
 

Evanski

Raccoon Lord
Forum Staff
Moderator
I was not able to reproduce using the exact code from the OP. It works as intended. Something else is wrong. Try clearing your cache(broom icon) and checking for other references to our_password

edit: Also you should be running this once with string_replace_all()

Code:
///Create
str = "2000000"
show_debug_message(str)
Code:
//Step
str = string_replace(str, 0, 1)

show_debug_message(str)
Code:
///Output
2000000
2100000
2110000
2111000
2111100
2111110
2111111
...
dgdfg.png

Clearing the cache still produces the error
 
B

Bayesian

Guest
try a fresh project. what os, version and runtime are you on?

edit: if it works in a fresh project try my code in the current one and post the output
 

Evanski

Raccoon Lord
Forum Staff
Moderator
try a fresh project. what os, version and runtime are you on?

edit: if it works in a fresh project try my code in the current one and post the output
New project:
Code:
2;111111
Windows 8.1, IDE v2.2.1.375, Runtime V2.2.1.291
 
B

Bayesian

Guest
So it seems they changed it in the last update, I don't think this is intentional since many functions in GML will convert to string for you but you have to use "" for it to work now. I'd report this and see what they say

Windows 7, IDE v2.2.1.375, Runtime V2.2.1.291

Code:
2�:�00000
2:��100
2:��110
2:��111
2:��111
2:��111
 
Top