Scripts/Creating Decisions (Need Help!)

I'm very new to this platform, but so far am getting the ropes fairly quickly based off the tutorials. A lot more I've figured out with ease on my own, however there is one thing I can't seem to figure out at all.

How do I create an interaction where you can make a choice, which then has different outcomes?

The closest I've gotten is creating a character in which you speak to, and then the character asks you a question in which you can respond yes or no.

However... I cannot seem to create a yes and no script separately, nor can I figure out how to create other choices such as ("slap the character" or "run for your life" as a few examples)

I've checked the tutorials over and over again and they simply don't cover this. I've checked other forum posts but can't seem to find anything either.

Any pointer's would be great!


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


concept:

there's typed-in inputs and menu selection inputs, which you have a VARIABLE store your input/selection, and then you use the 'if' or 'switch' Scripts/Functions to compare/contrast your input/selection stored within the VARIABLE to another (Integer:int in the first code box examples below) VARIABLE storing some (Integer:int in the first code box examples below) Value, and, if the VARIABLES' stored Values match up to each other, then you do whatever script/s for it, and/or if they don't match up, do (or don't do) whatever script/s for it

// an example

create (test) // creating a 'test' Object

test.score = GetRandomInt (0,100) // creating/setting a 'score' Integer Attribute for the 'test' Object, with a random Value of '0 to 100'

// based upon the 'test.score' Integer Attribute, this creates/sets the 'test.grade' String Attribute and its (String) Value:

// high to low example:

if (test.score > 89) {
  test.grade = "A"
} else if (test.score > 79) {
  test.grade = "B"
} else if (test.score > 69) {
  test.grade = "C"
} else if (test.score > 59) {
  test.grade = "D"
} else {
  test.grade = "F"
}

// you can also do 'greater/lesser than or equal to' as well (but it's an extra/unnecessary operation, though it's more clear in what you're doing, than in just doing greater/lesser than at '-1' Values):

(the equal sign HAS TO BE on the RIGHT SIDE of the '<,>' sign, and NO space between the '<,>' and the '=' signs)

if (test.score >= 90) {
  test.grade = "A"
} else if (test.score >= 80) {
  test.grade = "B"
} else if (test.score >= 70) {
  test.grade = "C"
} else if (test.score >= 60) {
  test.grade = "D"
} else {
  test.grade = "F"
}

// or, low to high, example:

if (test.score < 60) {
  test.grade = "F"
} else if (test.score < 70) {
  test.grade = "D"
} else if (test.score < 80) {
  test.grade = "C"
} else if (test.score < 90) {
  test.grade = "B"
} else {
  test.grade = "A"
}

there's also the built-in 'ask/Ask' Script/Function which does/handles binary (aka, 2 only) questions/choices, that you can use as well

(the difference between 'ask' and 'Ask' and any other Script/Function with upper and lower case: the lower case does a popup window and the upper case does an 'in-line' within the big text box on the left using blue hyperlinks)

ask ("Male?") {

  // quest (when using 'get input', 'ask/Ask', 'show menu / ShowMenu', etc) stores your choice automatically in the 'result' Variable VARIABLE:

  // if you chose 'yes', then: result = true
  // if you chose 'no', then: result = false

  if (result) { // if (result = true) {
    player.sex = "male"
  } else { // if (result = false) {
    player.sex = "female"
  }

  msg ("Player Sex: " + player.sex

}

String Matching, how it works:

get input {
  // you type in: dragon
  // result = "dragon"
}

if (result = "dragon") {
  msg ("MATCH!")
} else {
  msg ("NO match")
}

// if (result = "dragon") {
// [result = "dragon"]
// if ([result = "dragon"] = "dragon") {
// if (["dragon"] = "dragon") {
// if (["d"] = "d") { ---> true
// if (["r"] = "r") { ---> true
// if (["a"] = "a") { ---> true
// if (["g"] = "g") { ---> true
// if (["o"] = "o") { ---> true
// if (["n"] = "n") { ---> true
// if (["dragon"] = "dragon") { ---> TRUE ---> msg ("MATCH!")

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

VS

(quest IS case sensitive)

get input {
  // you type in: dragoN
  // result = "dragoN"
}

if (result = "dragon") {
  msg ("MATCH!")
} else {
  msg ("NO match")
}

// if (result = "dragon") {
// [result = "dragon"]
// if ([result = "dragoN"] = "dragon") {
// if (["dragoN"] = "dragon") {
// if (["d"] = "d") { ---> true
// if (["r"] = "r") { ---> true
// if (["a"] = "a") { ---> true
// if (["g"] = "g") { ---> true
// if (["o"] = "o") { ---> true
// if (["N"] = "n") { ---> false
// if (["dragoN"] = "dragon") { ---> FALSE ---> else { msg ("NO match") }

the above have been examples using the 'get input' (typed-in inputs) (the only other way of getting/using typed-in inputs, is via using Commands: http://docs.textadventures.co.uk/quest/elements/command.html , or in the GUI/Editor, on the left side's 'tree of stuff', under 'game', you'll see 'Commands')


so, here's some examples of using menu selections:

create ("example_object") // creates an 'example_object' Object

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

// creating/setting a 'sex_list' Stringlist Attribute on our 'example_object' Object:

example_object.sex_list = NewStringList ()

list add (example_object.sex_list, "male")

list add (example_object.sex_list, "female")

list add (example_object.sex_list, "hermaphrodite")

list add (example_object.sex_list, "asexual")

// or an alternative faster method (does NOT work for creating ObjectList Attributes):

example_object.sex_list = Split ("male;female;hermaphrodite;asexual", ";")

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

show menu ("Sex?", example_object.sex_list, false) {
  // remember, quest automatically sets: result = YOUR_TYPED_IN_INPUT_OR_YOUR_MENU_SELECTION
  player.sex = result
}

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

// some more examples:

show menu ("Sex?", example_object.sex_list, false) {
  if (result = "male") {
    msg ("you are a male")
  } else if (result = "female") {
    msg ("you are a female")
  } else if (result = "hermaphrodite") {
    msg ("you are a hermaphrodite")
  } else if (result = "asexual") {
    msg ("you are asexual")
  }
}

// example of using the 'switch' instead of the 'if' Script/Function:

show menu ("Sex?", example_object.sex_list, false) {
  switch (result) {
    case ("male") {
      msg ("you are a male")
    }
    case ("female") {
      msg ("you are a female")
    }
    case ("hermaphrodite") {
      msg ("you are a hermaphrodite")
    }
    case ("asexual") {
      msg ("you are asexual")
    }
  }
}

another example:

create ("king_npc")

king_npc.alias = "King"

king_npc.topics_list = NewStringList ()

list add (king_npc.topics_list, "princess")

list add (king_npc.topics_list, "dragon")

list add (king_npc.topics_list, "sword")

list add (king_npc.topics_list, "wizard")

king_npc.talk => {

  show menu ("Topic?", king_npc.topics_list, false) {
    switch (result) {
      case ("princess") {
        msg ("help! My daughter, the princess, has been kidnapped by the dragon! If you rescue her, I'll marry you to her and you'll become the new king after I die!")
      }
      case ("dragon") {
        msg ("The dragon can only be killed by the legendary dragon slayer sword")
      }
      case ("sword") {
        msg ("the legendary dragon slayer sword, is believed to be in the posession of a wizard")
      }
      case ("wizard") {
        msg ("the wizard will not hand over the sword... you can find him in his tower deep in the dark forest")
      }
    }
  }

}

using a String Dictionary instead of a String List:

create ("king_npc")

king_npc.alias = "King"

king_npc.topics_dict = NewStringDictionary ()

dictionary add (king_npc.topics_dict, "princess", "help! My daughter, the princess, has been kidnapped by the dragon! If you rescue her, I'll marry you to her and you'll become the new king after I die!")

dictionary add (king_npc.topics_dict, "dragon", "The dragon can only be killed by the legendary dragon slayer sword")

dictionary add (king_npc.topics_dict, "sword", "the legendary dragon slayer sword, is believed to be in the posession of a wizard")

dictionary add (king_npc.topics_dict, "wizard", "the wizard will not hand over the sword... you can find him in his tower deep in the dark forest")

// this is how you create a 'script' Attribute (Script Attribute = Verb which has etc built-in coding for it to work as a Verb):

// ( http://docs.textadventures.co.uk/quest/scripts/setting_variables.html )

king_npc.talk => {

  show menu ("Topic?", king_npc.topics_dict, false) {

    string_variable = StringDictionaryItem (king_npc.topics_dict, result)

    msg (string_variable)

  }

}

links:

http://docs.textadventures.co.uk/quest/scripts/if.html
http://docs.textadventures.co.uk/quest/scripts/switch.html

http://docs.textadventures.co.uk/quest/scripts/ask.html

http://docs.textadventures.co.uk/quest/scripts/get_input.html

http://docs.textadventures.co.uk/quest/using_lists.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html

http://docs.textadventures.co.uk/quest/functions/getrandomint.html

http://docs.textadventures.co.uk/quest/scripts/setting_variables.html


P.S.

my 'princess/dragon/sword/wizard' item 'keys', don't have to be single words as I've done, you can instead have them as sentences/paragraphs:


using a String Dictionary instead of a String List:

create ("king_npc")

king_npc.alias = "King"

king_npc.topics_dict = NewStringDictionary ()

dictionary add (king_npc.topics_dict, "Ask about the young beautiful sexy princess!", "help! My daughter, the princess, has been kidnapped by the dragon! If you rescue her, I'll marry you to her and you'll become the new king after I die!")

dictionary add (king_npc.topics_dict, "Ask about the dark dragon of destruction", "The dragon can only be killed by the legendary dragon slayer sword")

dictionary add (king_npc.topics_dict, "Ask about the legendary dragon slayer sword of the gods", "the legendary dragon slayer sword, is believed to be in the posession of a wizard")

dictionary add (king_npc.topics_dict, "Ask about the evil wizard of vile taint", "the wizard will not hand over the sword... you can find him in his tower deep in the dark forest")

// this is how you create a 'script' Attribute (Script Attribute = Verb which has etc built-in coding for it to work as a Verb):

// ( http://docs.textadventures.co.uk/quest/scripts/setting_variables.html )

king_npc.talk => {

  show menu ("Topic?", king_npc.topics_dict, false) {

    string_variable = StringDictionaryItem (king_npc.topics_dict, result)

    msg (string_variable)

  }
}

P.S.S.

Pixie already created a 'dialogue/topic/conversation' system/library that you can use, I think it's already built-into/added-to quest already, and if you need help with using it, someone else can help you, as I've not tried using it yet, so I don't know how to use it and can't be of help to you with it, but again, others can/will help you with using it.


@hegemonkhan

I am not using quest via code. I'm using the online editor with all the commands and tabs and what not. Is there a way to do this via those means?


Maybe if.
blah

if (room.light = true) {
  msg ( "The light is on")
}
else {
  msg ("The light is off." )
}

Or you can try a ShowMenu! The most common way is like this (change code as needed):

game.rooms = NewObjectList()
list add (game.rooms, The Lab)
list remove (game.rooms, player.parent)
if (game.firstteleport = true) {
  ShowMenu ("Teleport", game.rooms, true) {
    list add (game.rooms, player.parent)
    MoveObject (player, GetObject(result))
  }
}
else {
  list add (game.rooms, player.parent)
  msg ("...It didn't work...")
}

But I think this is the simplest way (change code as needed):

msg ("See something that catches your eye?")
options = Split("Potion (100);Hyper Potion (200)", ";")
ShowMenu ("Shop", options, true) {
  switch (result) {
    case ("Potion (100)") {
      if (player.gold >= 100) {
        player.gold = player.gold - 100
        player.potion = player.potion + 1
        msg ("You bought a Potion.")
      }
      else {
        msg ("You don't have enough gold.")
      }
    }
    case ("Hyper Potion (200)") {
      if (player.gold >= 200) {
        player.gold = player.gold - 200
        player.hyper_potion = player.hyper_potion + 1
        msg ("You bought a Hyper Potion.")
      }
      else {
        msg ("You don't have enough gold.")
      }
    }
  }
}

If possible, please use the downloaded version. Working with the desktop version is far more flexible and dynamic than the online version. If you must work with the online version, I can still help. I think...


Some documentation:

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

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


here's more links as well:

http://textadventures.co.uk/forum/general/topic/ljjm32av4e2t9ot49k478g/help#710be61e-eae1-4af1-8363-520cc718ba1c

(specifically, look at the 'hk attributes and if script usage guide' link, and within it, scroll down past the general concept of quest and its coding, to about 1/4 to 1/3 of the way down the post, to 'the two super scripts: attributes and the if script' section, and start reading from there, as I do show how to do the stuff both in code and via within the GUI/Editor using its Tabs/controls/options)


and here's an example creating your own demo game, in learning Attributes and status attributes (stringdictionary attributes) usage specifically, as it also involves how to do the stuff via using the GUI/Editor's Tabs/controls/options, as well:

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#p37375


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

Support

Forums