GM:S 1.4 if estatement following another "if" not working

Discussion in 'Legacy GameMaker Community Tech Support' started by Rick Silva, Dec 18, 2018.

  1. Rick Silva

    Rick Silva Member

    Joined:
    Dec 24, 2016
    Posts:
    6
    well, for starters I managed to figure out how to make my code work, but I didn't like the solution. thing is, I put two "if" estatements together, with the same function, and one of them didn't work. so I simply skipped a line of code and voilá, works like a charm. what gives? what am I missing?

    here are the two codes. I'm making a textbox script from scratch, so the idea is that a text is given and the object prints it on screen letter by letter, but i want it to stop at a certain point (so I can wait for user imput to go to the next page)

    in the code that doesn't work, the variable "localcheckspaces" won't change its starting value:

    if (wait = false)
    {
    charcount += 1;
    localcharcount+=1;

    if(string_char_at(text,charcount) == " " )
    {checkspaces = charcount };

    if (string_char_at(textecho,localcharcount)==" ") //HERE IS THE LINE THAT DOESN'T WORK
    {localcheckspaces = localcharcount };

    textecho = string_copy(text,startfrom,localcharcount);

    if (charcount > string_length(text))
    {charcount = string_length(text)
    wait=true};
    }

    if (wait=true)
    {textecho = string_copy(text,startfrom,localcheckspaces) }

    here is the code that WORKS

    if (wait = false)
    {
    charcount += 1;
    localcharcount+=1;

    if(string_char_at(text,charcount) == " " )
    {checkspaces = charcount };

    textecho = string_copy(text,startfrom,localcharcount);

    if (string_char_at(textecho,localcharcount)==" ") //PUTTING HERE WILL MAKE IT WORK
    {localcheckspaces = localcharcount };

    if (charcount > string_length(text))
    {charcount = string_length(text)
    wait=true};
    }

    if (wait=true)
    {textecho = string_copy(text,startfrom,localcheckspaces) }
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,695
    Your second if statement references textecho, that means it must come after the line that gives textecho its value.
     
  3. Rick Silva

    Rick Silva Member

    Joined:
    Dec 24, 2016
    Posts:
    6
    yeah, I thought that too, but when I put the code like this, it also works. besides, "textecho" is declared inside the "create" event. my point is, if the if estatements won`t work when I put the same function inside sucessive ifs, I`ll have to rearrange other parts of my code

    if (wait = false)
    {
    if (string_char_at(textecho,localcharcount)==" ") //HERE IS THE LINE
    {localcheckspaces = localcharcount };

    charcount += 1;
    localcharcount+=1;

    if(string_char_at(text,charcount) == " " )
    {checkspaces = charcount };


    textecho = string_copy(text,startfrom,localcharcount);



    if (charcount > string_length(text))
    {charcount = string_length(text)
    wait=true};
    }

    if (wait=true)
    {textecho = string_copy(text,startfrom,localcheckspaces)};
     

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