Inserting information in a message based on attribute value

So what I want to do is have a dialogue message, but have one part of it to be determined by an attribute, in this case the player's gender.
So
"Hi nice to me you, (Gender specific sentance),
If gender = Male then "You must work out."
If gender = Female then "I like what you did with your hair."
I have no idea how to go about this?


I think it would be: "Hi, nice to meet you, {either player.gender="Male":you must work out.|I like what you did with your hair.}"


Or, if you wanted it to miss out the gender specific sentence if gender is anything other than Male or Female, you'd use:
"Hi, nice to meet you{if player.gender="Male":. You must work out}{if player.gender="Female":, I like what you did with your hair}."


the quickest/easiest method is using the text processor commands:

http://docs.textadventures.co.uk/quest/text_processor.html


http://docs.textadventures.co.uk/quest/elements/object.html

http://docs.textadventures.co.uk/quest/attributes/article.html
http://docs.textadventures.co.uk/quest/attributes/gender.html


for example (using your example):

game.sex_list = NewStringList ()
list add (game.sex_list, "male")
list add (game.sex_list, "female")

player.alias = "HK"

player.sex = StringListItem (game.sex_list, GetRandomInt (0, ListCount (game.sex_list) - 1))

msg ("Hi, nice to meet you, {player.alias}. {if player.sex = "male":You must work out}{if player.sex = "female":I like what you did with your hair}.")

or, you can the "normal" scripting method (uses concatenation):

game.sex_list = NewStringList ()
list add (game.sex_list, "male")
list add (game.sex_list, "female")

player.alias = "HK"

player.sex = StringListItem (game.sex_list, GetRandomInt (0, ListCount (game.sex_list) - 1))

concatenation_string_variable = "Hi, nice to meet you, " + player.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 + " I like what you did with your hair."
}

msg (concatenation_string_variable)

@HK
This is harder to read than it needs to be:

player.sex = StringListItem (game.sex_list, GetRandomInt (0, ListCount (game.sex_list) - 1))

You could shorten it by using the core function:
player.sex = PickOneString (game.sex_list)

You also have:

game.sex_list = NewStringList ()
list add (game.sex_list, "male")
list add (game.sex_list, "female")

where it could easily be:
game.sex_list = Split("male;female")

It's good to know how to do it the longer way, because there are cases where it's necessary. But when explaining the fundamental concepts, I think it's better to show a new user the simpler way first. If you give someone a whole bunch of code that's a lot more complex than it needs to be, they're likely to get into the habit of just copy-pasting what you give them rather than trying to understand it.


I've not yet learned all of these new Functions/Scripts that Pixie (and you guys) has been adding to the engine with his updates to it, so I still use the old stuff of last version before Pixie's been updating the engine.

I'm still using the old version, so that's why I've not learned of all of these new features that Pixie (and you guys) has been adding


I generally show the 'new + add' (unless I'm really lazy) because you can't use the 'split' with/for generating an Object List, it only works with/for String Lists.

Also, for/to me, the 'new + add' is more clear and self-explanatory, whereas, 'Split' is not at all so in what and how it's doing what its doing


I somewhat usually (unless lazy, like in this case, lol) break down the 'string list item' functionality into multiple individual code lines to show how it works... but this was just a quick help post, so I was lazy and just did it as a single code line instead.


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


@ Thickar:

if you're interested (hopefully can understand all this stuff, as it is a bit advanced stuff)...

here's what's actually being done with this complex code line in my previous post: player.sex = StringListItem (game.sex_list, GetRandomInt (0, ListCount (game.sex_list) - 1)), see below:

list_count_integer_variable = ListCount (game.sex_list)

// a list's items' index numbers start at '0', not '1', and so the...

index_number_of_last_item_in_list_integer_variable = list_count_integer_variable - 1

viable_selected_random_integer_variable = GetRandomInt (0, index_number_of_last_item_in_list_integer_variable)

selected_random_menu_item_(aka_returned_output)_string_variable = StringListItem (game.sex_list, viable_selected_random_integer_variable)

player.sex_string_attribute = selected_random_menu_item_(aka_returned_output)_string_variable


the 'range' (or 'bounds') of any list:

(inclusive)
0 to ListCount (LIST) - 1

(exclusive)
-1 to ListCount (LIST)

so:

-1 < "IN BOUNDS" < ListCount (LIST)

["OUT OF BOUNDS" < 0] and [ListCount (LIST) - 1 < "OUT OF BOUNDS"]


game.example_stringlist_attribute = NewStringList ()
list add (game.example_stringlist_attribute, "red")
list add (game.example_stringlist_attribute, "blue")
list add (game.example_stringlist_attribute, "yellow")

item 1 (first item added to list):
input (String) ('key') ('index number'): 0
output (String) ('value'): "red"

item 2 (second item added to list):
input (String) ('key') ('index number'): 1
output (String) ('value'): "blue"

item 3 (third and last item added to list):
input (String) ('key') ('index number'): 2
output (String) ('value'): "yellow"

there is no 4th item, and so there is no '3' index number (input "key")... see below:

VARIABLE = [RETURNED_OUTPUT <==== StringListItem (LIST, INPUT)]

string_variable = StringListItem (game.example_stringlist_attribute, 0)
msg (string_variable)
// output/display: red

string_variable = StringListItem (game.example_stringlist_attribute, 1)
msg (string_variable)
// output/display: blue

string_variable = StringListItem (game.example_stringlist_attribute, 2)
msg (string_variable)
// output/display: yellow

string_variable = StringListItem (game.example_stringlist_attribute, 3)
msg (string_variable)
// output/display: ERROR! (there is no 4th item in the list: "Out of Bounds" ERROR)


@hegemonkhan
I tired the first code you gave me after suggesting processor commands
and got this message
Error running script: Error compiling expression 'female': Unknown object or variable 'female'


can you post your code you used?, and we'll correct/fix it up for you


in your 'if' Script, make sure the Value in the conditional expression has double quotes, and make sure all of your name spellings (Object Name, Attribute Name, and Value) are the same (in both the 'if' scripting and every where else), for example:

// the 'if' Script/Function Block:

if (CONDITIONAL_EXPRESSION_1) {
} else if (CONDITIONAL_EXPRESSION_2) {
}

// ---------------------

CONDITIONAL means string matching:

create ("example_object")

example_object.example_string_attribute = "dragon"

if (example_object.example_string_attribute = "dragon") {
  msg ("it matches!")
}

// here's how it works (what it's actually doing):

example_object.example_string_attribute = "dragon"

if (example_object.example_string_attribute = "dragon")
if ("dragon" = "dragon")
  if ("d" = "d")
    if ("r" = "r")
      if ("a" = "a")
       if ("g" = "g")
         if ("o" = "o")
           if ("n" = "n")
             // TRUE ("dragon" = "dragon") --> output/display: it matches!

vs if it's not a match (quest IS case sensitive):

example_object.example_string_attribute = "dragoN"

if (example_object.example_string_attribute = "dragon")
if ("dragoN" = "dragon")
  if ("d" = "d")
    if ("r" = "r")
      if ("a" = "a")
       if ("g" = "g")
         if ("o" = "o")
           if ("N" = "n") ---> FAIL ("dragoN" NOT = "dragon")

vs

example_object.example_string_attribute = "dmagon"

if (example_object.example_string_attribute = "dragon")
if ("dmagon" = "dragon")
  if ("d" = "d")
    if ("m" = "r") ---> FAIL ("dmagon" NOT = "dragon")

vs

example_object.example_string_attribute = "dragon"

if (example_object.example_string_attribute = "Dragon")
if ("dragon" = "Dragon")
  if ("d" = "D") ---> FAIL ("dragon" NOT = "Dragon")

vs

example_object.example_string_attribute = "dragon"

if (example_object.example_string_attribute = "dragoN")
if ("dragon" = "dragoN")
  if ("d" = "d")
    if ("r" = "r")
      if ("a" = "a")
       if ("g" = "g")
         if ("o" = "o")
           if ("n" = "N") ---> FAIL ("dragon" NOT = "dragoN")

// ----------------------

A String Attribute CONDITIONAL_EXPRESSION:

if (NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = "STRING_VALUE_1") {
} else if (NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = "STRING_VALUE_2") {
}

// -----------------

game.sex_stringlist_attribute = Split ("male;female", ";")

// or:

game.sex_stringlist_attribute = NewStringList ()
list add (game.sex_stringlist_attribute, "male")
list add (game.sex_stringlist_attribute, "female")

// ------------

// the 'PickOneString' Script/Function is a 'helper' Script/Function, doing the scripting for you (see the first '// or' just a bit further below):

player.sex_string_attribute = PickOneString (game.sex_stringlist_attribute)

// or (this is what the 'PickOneString' helper Script/Function is doing for you):

player.sex_string_attribute = StringListItem (game.sex_stringlist_attribute, GetRandomInt (0, ListCount (game.sex_stringlist_attribute) - 1))

// or (breaking down the above):

list_count_integer_variable = ListCount (game.sex_stringlist_attribute)

index_number_of_last_item_in_list_integer_variable = list_count_integer_variable - 1

index_number_of_first_item_in_list_integer_variable = 0

random_in_bounds_index_number_of_list_integer_variable = GetRandomInt (index_number_of_first_item_in_list_integer_variable, index_number_of_last_item_in_list_integer_variable)

random_selected_string_value_of_list_string_variable = StringListItem (game.sex_stringlist_attribute, random_in_bounds_index_number_of_list_integer_variable)

player.sex_string_attribute = random_selected_string_value_of_list_string_variable
// player.sex_string_attribute = (randomly selected: "male" or "female")

// ----------

if (player.sex_string_attribute = "male") {
} else if ((player.sex_string_attribute = "female") {
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums