Error in this specific code? (Easy to Read Color Coding)

Discussion in 'Programming' started by MotherlandRuskiushi, Apr 4, 2019.

Tags:
  1. MotherlandRuskiushi

    MotherlandRuskiushi Member

    Joined:
    Apr 4, 2019
    Posts:
    2

    if
    (currCharIndes < string_length(text[convoIndex, 1]) +1);​
    {
    spriteToDisplay = dialogue[convoIndex, 0];
    stringToDisplay += string_char_at(dialogue[convoIndex, 1], currCharIndex++);​

    else // ( The Error is here apparently, why?)
    {
    if (keyboard_check_pressed(vk_space))​
    {
    convoIndex++;
    stringToDisplay = "";
    currCharIndex = 1;​
    if (convoIndex == convodialogueCount)​
    {
    active = false;​
    }
    }

    }
     
    Last edited: Apr 4, 2019
  2. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    824
    I'm guessing it is because you are missing the } before the else.
    Would be helpful if you would post code in code tags (the guidelines have how to do that), and if you are getting an error you should really be showing us what the error is.
     
  3. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,155
    The error is actually here:

    If statements don't have a semi-colon at the end if you want them to be any use.

    Because you have a semi-colon, GMS treats it as the end of the if() statement, so when it see the rogue "else" further down below with no matching if() previously, it throws an error.

    Edit: @BaBiA Game Studio is also correct, you are missing a } there.
     
    BaBiA Game Studio likes this.
  4. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    824
    It would have been a lot easier to spot all the problems if the actual error message had been provided, and if there was no colouring of text being done.
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    Even the fanciest color coding won't make code readable when you have three closing curly braces (and all of them in general) on the same horizontal position because you didn't wrap them in a code tag and the blank space filter gobbled them up. I can see the original formatting when editing the post, but... :p

    You can find further information regarding how to most efficiently post code and questions in general in the guidelines and How to Q&A.
     
  6. dannyjenn

    dannyjenn Member

    Joined:
    Jul 29, 2017
    Posts:
    568
    I like the color coding :) But yeah, users BaBiA Game Studio and TsukaYuriko make some good points.

    Also, in addition to the two problems which have already been mentioned, I see that on the first line you misspelled currCharIndex as currCharIndes. That has nothing to do with the error you're getting, but it will cause problems if you don't fix it. I'm not sure if anything else is wrong.
     
    MotherlandRuskiushi likes this.
  7. MotherlandRuskiushi

    MotherlandRuskiushi Member

    Joined:
    Apr 4, 2019
    Posts:
    2
    Thank you all for your helpful replies, I now changed the subject as I completely fixed the problem. Now I just have a normal question

    New problem, I want to enter a new room (for story telling purposes) after I'm done talking to an NPC.

    (Context: The child (player) finds himself in a pitch-black area, in front of him is a man in red; he is bald. The child (player) speaks to him, and is then asked if he is lost. After a brief conversation, the man begins to explain what he means by "lost".) And that's where I want to go to a new room.​
     
  8. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,536
    (Please don't change topic titles or contents after problems have been solved. I reverted the topic to its original state to avoid confusion.)

    You've only told us what you're trying to do, but not what issues you're facing with this. Please let us know what you have tried and which problems you ran into so that we can help you resolve them.​
     

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