1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

[SOLVED] Adding a String to an existing string

Discussion in 'Programming' started by EMm, Mar 4, 2017.

Tags:
  1. EMm

    EMm Guest

    So my game is a choose your own adventure style game where the player makes decisions and depending on those decisions they go to certain rooms. I'm trying to make it so theres a string which checks which decision you made and then adds it to an existing string, which then prints on an end screen to show which choices the player made. right now I have:

    In the event the player presses the 1 key -

    var roomName = room_get_name(room)
    global.Choices = "You chose to:";

    if roomName = "rm_j1" {
    global.Choices += " Be diplomatic,"
    }

    if roomName = "rm_jw1" {
    global.Choices += " Agree with the President"
    }


    which then prints in a seperate object.

    However, the issue I'm having is the variable global.choices is not re setting to the new vaule of global.Choices and is just using the variable set at the top of the code.

    I would like it to print:
    "You chose to: Be diplomatic, Agree with the president"

    But its only printing:
    "You chose to: Agree with the President"

    I was wondering if anyone could help me understand what is going wrong and how to add each string to the one initialized, without getting rid of the previous one.
     
  2. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    In the very first line you use a regular assignment rather than an addition.
     
  3. Tthecreator

    Tthecreator Your Creator!

    Joined:
    Jun 20, 2016
    Posts:
    757
    What I'm seeing here is that whenever the key is pressed, global.Choices is reset to "You chose to:"

    Lets get an example:
    You press the 1 button in rm_j1 then the following will happen:
    global.Choices = "You chose to:";
    global.Choices += " Be diplomatic,"

    Now you continue to rm_jw1 and then this will happen:
    global.Choices = "You chose to:";
    global.Choices += " Agree with the President"

    Are you seeing what is happening? You are resetting global.Choices over and over again, while you are only in a single room at a time.
    What you should do is set global.Choices once when starting the game and then never again.
     
  4. EMm

    EMm Guest

    Oh my goodness thank you so much! I dont know why I couldnt think of that
     

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