Having trouble inserting attribute value in as dialouge

Okay so I recently asked the question how do I have a sentence in a dialouge change depending on the atrribute of a value.
So like whether the player gender is male or female. for example
(Dialogue)
"Nice to meet you,{Gender specific answer}.
If player.gender = "male" {
you must work out
}
If player.gender = "female" {
I love what you have done with your hair
}

Now I got some answers but they were to have to understand so having been able to cobble together my own solutions from bits and pieces of other's solutions I took a shot at it but I'm getting an error
So when entering the room the player starts in they are automiatically asked to select their gender.
Then they are transported to another room, where there is an NPC who they can talk to. When they do their first option of conversation topic is saying hello, where in that dialogue the gender specific sentence is called.
It's when I select the option to say hello I get this error

Error running script: Error compiling expression 'player.sex = male': Unknown object or variable 'male'

options = Split("Male;Female", ";")
ShowMenu ("What is your Gender?", options, false) {
  switch (result) {
    case ("Male") {
      msg ("So you are a man.")
      player.sex = "male"
    }
    case ("Female") {
      msg ("So you are Female.")
      player.sex = "female"
    }
  }
  MoveObject (player, Exercise Room)
}

Say hello script

if (player.sex = male) {
  sarah.gender_answer = "My name is Sara, you must work out"
}
else if (player.sex = female) {
 sarah.gender_answer = "My name is Sara, and I love what you have done with your hair"
}
msg ("\"Hello, nice to meet you, my name is {player.custom_name} \". You say enthusiastically holding out your hand.<br/>She grabs it firmly, and has quite a grip.<br/>\"{sarah.gender_answer},\" She replies with a warm smile\"")

if (player.sex = male) {
else if (player.sex = female) {

These should be:

if (player.sex = "male") {
else if (player.sex = "female") {

"male" and "female" are string values so need quotes. Without quotes they are treated as objects (presumably you don't have male and female objects in your game).


(filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)


quest is case sensitive too, make sure your upper/lower case matches up (spelling and upper/lower case must be exact, NO TYPOS ALLOWED in coding!)


an example:

<game name="example_game">

  <attr name="pov" type="object">player</attr>

  <attr name="start" type="script">

    msg ("Name?")

    get input {

      player.alias = result

      options = Split ("male;female", ";")

      ShowMenu ("What is your Sex?", options, false) {

        player.sex = result

        msg ("So, you're a " + player.sex + ".")
        // or:
        // msg ("So, you're a {player.sex}.")

        player.parent = exercise_room
        // or:
        // MoveObject (player, exercise_room)

        do (npc_1_object, "greet")

      }

    }

  </attr>

</game>

<object name="player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="parent" type="object">room</attr>

  <attr name="pov_alias" type="string">unknown</attr>

  <attr name="sex" type="string">unknown</attr>

   <!--
   the 'look' String/Script Attribute is for when the Object is NOT currently being controlled by you
   
   the 'pov_look' String/Script Attribute is for when the Object IS currently being controlled by you
   -->

  <attr name="pov_look" type="script">

    concatenation_string_variable = "Nice to meet you, " + player.sex + "."
    // or:
    // concatenation_string_variable = "Nice to meet you, {player.sex}."

    if player.sex = "male" {
      concatenation_string_variable = concatenation_string_variable + " You must work out."
    } else if (player.sex = "female" {
      concatenation_string_variable = concatenation_string_variable + " I love what you have done with your hair."
    }

    on ready {
      msg (concatenation_string_variable)
    }

  </attr>

</object>

<object name="npc_1_object">

  <inherit name="editor_object" />

  <attr name="parent" type="object">exercise_room</attr>

  <attr name="alias" type="string">Sarah</attr>

  <attr name="sex_answer" type="string">unknown</attr>

  <displayverbs type="listextend">

    <value>greet</value>

  </displayverbs>

  <attr name="greet" type="script">

    concatenation_string_variable = "My name is " + npc_1_object.alias + ", "
    // or:
    // concatenation_string_variable = "My name is {npc_1_object.alias}, "

    if (player.sex = "male") {
      concatenation_string_variable = concatenation_string_variable + "you must work out."
    } else if (player.sex = "female") {
      concatenation_string_variable = concatenation_string_variable + "and I love what you have done with your hair."
    }

    on ready {

      npc_1_object.sex_answer = concatenation_string_variable

      msg ("\"Hello, nice to meet you, {npc_1_object.alias}. My name is {player.alias}.\" You say enthusiastically holding out your hand.")
      msg ("")
      msg ("She grabs it firmly, and has quite a grip.")
      msg ("")
      msg ("\"{npc_1_object.sex_answer},\" She replies with a warm smile.")

    }

  </attr>
  
</object>

<object name="room">

  <inherit name="editor_room" />

</object>

<object name="exercise_room">

  <inherit name="editor_room" />

</object>

<verb>

  <property>greet</property>
  <pattern>greet</pattern>
  <defaultexpression>You can't greet that!</defaultexpression>

</verb>

err... jsut realized that the stuff of yours that I put into the 'pov_look' String/Script Attribute on the 'player' Player Object, should be put into the 'greet' String/Script Attribute (Verb) on the 'npc_1_object' (Sarah) Object... but am too lazy to fix it up...


Also, you don't need an 'else if' statement nested under the 'if' statement, if you only have male and female. All you need is the 'else' statement, which covers everything other than male.

if (player.sex = "male") {"You must work out," she said.}
else {"Wow, nice... ahems and... ahem," she said.}

Log in to post a reply.

Support

Forums