[SOLVED} Choices after player takes object into room?

A friend has written an alternate ending for me, but it involves the player choosing options and I do not know how to program such things...

To be more clear: After taking npc object into room where another npc is, the resident npc gives the player options to do with the guest npc.


here's some links to help you:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

for the choosing options and (then acting upon the chosen option), using lists, and the 'if' or 'switch' Scripts/Functions :

http://docs.textadventures.co.uk/quest/using_lists.html
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk

http://docs.textadventures.co.uk/quest/guides/character_creation.html

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


if you need more help or still need help, let us know, we'd be glad to help you!


'switch' is not apropriate
and I have trouble understanding stuff written out like
msg(ListItem(l, 3))
// -> 42
list remove(l, fancy table)
msg(ListItem(l, 3))
// -> 9.23

Can you please help me in your own words?


This is how I would try it, but I'm a beginner by myself. I know how overhelming this can be . I try it.

You can start the script as you talk to the resident or after entering the room (go to the room object's Script tab >> 'Run script after entering the room')

Start it with a 'If' condition. There are multiple ways to check if you have the guest npc with you or not. For example, you add a flag to the player if he got the guest npc and select 'if' >> 'object has flag' and select player and type the flag.

or select 'if' >> 'expression' >> (Put this in the text box:) guest_npc.parent = player.parent
The parent attribute of the player is the room you're in. So, if you put this expression (guest_npc.parent = player.parent)as condition the game is checking if the guest_npc have the same parent as the player, in other words, is in the same room as the player.

Then you can add the script for choosing a option. I think the easiest way is to use Show Menu and Switch.

You select 'show menu
You can enter a text and question in the first text box, but this text will disappear after choosing. If you want the question to stay put a normal message before Show Menu and leave this box empty.

In the second text box, (Options from list/dictionary:), is where you can add the choices to select from. (It's possible to get choice options from a list, but I think it's for beginners easier without.) Okay, type this into the second text box (Options from list/dictionary:)
Split ("The first option.";"The second option.";"The third option.",";")
You can copy this and insert your options.

Then you can select to allow the player to ignore the question or not. If the player can't ignore the menu he can do nothing until he picks a option.

Now, 'After choosing, run script:'
Here you need to insert the script to what happens after the player selected a option.

It is the 'Switch' (add new script >> Scripts tab >> Switch...)
In the first text box you type: result

result is the temporary value you've got by selecting a option in the menu.

Next stop are cases.
If you click on add, a text box appears. Here can you type the options from Show Menu again, but only one of the choices for each case.
Then you add another case and type the second option and then the third. The cases must have quotations marks and the same spelling as before:
"The first option."
"The second option."
"The third option."

Now you can add the scripts you want for each case and what happens after the player picked a option.


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


here's an example game:


I did the options as Verbs, but it you want them as a menu of choices instead, let me know, and I'll provide an example game code using this method instead


(if you need me to explain anything, let me know)

(hopefully this will work with Pixie's current version of quest... if not... let me know)

(hopefully, I've got no mistakes in my code below, lol, if it doesn't work or anything doesn't work, let me know!)

  1. create a new text adventure quest game: name it whatever and save it some where you can find it (like the desktop)

  2. right click on your 'whatever.aslx' new game file that you just created, and choose to 'open' it, selecting a text editor software (notepad, wordpad, Apple: text editor, etc) to open it with

  3. this is your entire game code, which, you will: highlight all of it, and then delete all of it!

  4. now, highlight my entire code in the code box below, copy it, paste it into your blank 'whatever.aslx' game file, save it, and then close out of it.

  5. now, just open up your 'whatever.aslx' game file normally in the quest GUI/Editor and study it, as well as try playing it too

you may need to change the '<asl version="550">' to whatever the current version, for example, '<asl version="580">', of quest of Pixie's updates

<asl version="550">

  <include ref="English.aslx" />

  <include ref="Core.aslx" />

  <game name="example_game">

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

      msg ("Type in 'warp room' or 'warp room_2' to switch rooms") 

    </attr>

  </game>

  <object name="room">

    <inherit name="editor_room" />

  </object>

  <object name="room_2">

    <inherit name="editor_room" />

  </object>

  <object name="player">

    <inherit name="editor_object" />

    <inherit name="editor_player" />

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

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

      if (npc_1.following) {
       npc_1.parent = player.parent
      }

    </attr>

  </object>

  <object name="npc_1">

    <inherit name="editor_object" />

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

    <attr name="take" type="boolean">false</attr>

    <attr name="drop" type="boolean">false</attr>

    <attr name="following" type="boolean">false</attr>

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

      if (npc_1.parent = npc_2.parent) {
        if (ListContains (npc_2.displayverbs, "cast")) {
          msg ("Click on the 'cast' Verb on 'npc_2' to win this example game") 
        } else {
          msg ("Go 'talk' to 'npc_2' now")
        }
      } else {
        ask ("Want me to follow you? (Also, if I'm already following you, and you select 'no', then I'll stop following you)") {
          if (result) {
            if (npc_1.following) {
              msg ("I'm already following you, silly")
            } else {
              npc_1.following = true
              msg ("Okay, I'm now following you!")
            }
          } else {
            if (npc_1.following) {
              npc_1.following = false
              msg ("Okay, I'm now NOT following you anymore")
            } else {
              msg ("I'm already NOT following you, silly")
            }
          }
        }
      }

    </attr>

  </object>

  <object name="npc_2">

    <inherit name="editor_object" />

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

    <attr name="take" type="boolean">false</attr>

    <attr name="drop" type="boolean">false</attr>

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

      if (npc_1.parent = npc_2.parent) {
        if (ListContains (npc_2.displayverbs, "cast")) {
          msg ("You may now select the 'cast' Verb on me to do the spell to win this example game for you")
        } else {
          list add (npc_2.displayverbs, "cast")
          msg ("Ah, you brought 'npc_1', to me, you may now select the 'cast' Verb on me to do the spell to win this example game for you")
        }
      } else {
        msg ("I will not 'cast' the spell for you to win this example game, until you bring 'npc_1' to me")
      }

    </attr>

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

      msg ("You've won this example game, congradulations!")
      finish

    </attr>

    <attr name="displayverbs" type="stringlist">

      <value>talk</value>

    </attr>

  </object>

  <verb>

    <property>talk</property>

    <pattern>talk</pattern>

    <defaultexpression>You can't talk to that!</defaultexpression>

  </verb>

  <verb>

    <property>cast</property>

    <pattern>cast</pattern>

    <defaultexpression>You can't cast that!</defaultexpression>

  </verb>

  <command name="warp_command">

    <pattern>warp #object_parameter#</pattern>

    <script>

      if (object_parameter = room or object_parameter = room_2) {
        if (player.parent = object_parameter) {
          msg ("You're already in the '" + object_parameter.name + "' room, silly.")
        } else {
          player.parent = object_parameter
          msg ("You warp to the '" + object_parameter.name + "' room")
        }
      } else {
        msg ("Wrong input, type in 'warp room' or 'warp room_2', when you try again")
      }

    </script>

    <unresolved>Wrong input, type in the name of an Object that exists in this example game, next time</unresolved>

  </command>

</asl>

P.S.

this link (from my first post in this thread, repeated again in this post) shows you how to do a menu list of choices/options:

http://docs.textadventures.co.uk/quest/guides/character_creation.html

ask if you need help with anything!


(filler for getting my edited post, updated/psoted)


the 'if' and 'switch' Scripts/Functions are exactly the same, it's only a matter of aesthetics between them


example 1:

viable_random_integer_variable = GetRandomInt (0, 2)

game.state_integer_attribute = viable_random_integer_variable 

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

if (game.state_integer_attribute = 0) {
  msg ("Game State: 0")
}
else if (game.state_integer_attribute = 1) {
  msg ("Game State: 1")
}
else {
  msg ("Game State: 2")
}

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

switch (game.state_integer_attribute) {
  case (0) {
    msg ("Game State: 0")
  }
  case (1) {
    msg ("Game State: 1")
  }
  default {
    msg ("Game State: 2")
  }
}

example 2

game.condition_stringlist_attribute = NewStringList ()

list add (game.condition_stringlist_attribute, "poisoned")
list add (game.condition_stringlist_attribute, "petrified")
list add (game.condition_stringlist_attribute, "paralyzed")

list_count_integer_variable = ListCount (game.condition_stringlist_attribute)

last_list_item_index_number_integer_variable = list_count_integer_variable - 1

viable_random_integer_variable = GetRandomInt (0, last_list_item_index_number_integer_variable)

viable_random_string_variable = StringListItem (game.condition_stringlist_attribute, viable_random_integer_variable)

player.condition_string_attribute = viable_random_string_variable

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

if (player.condition_string_attribute = "poisoned") {
  msg ("Player Condition: poisoned")
}
else if (player.condition_string_attribute = "petrified") {
  msg ("Player Condition: petrified")
}
else {
  msg ("Player Condition: paralyzed")
}

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

switch (player.condition_string_attribute) {
  case ("poisoned") {
    msg ("Player Condition: poisoned")
  }
  case ("petrified") {
    msg ("Player Condition: petrified")
  }
  default {
    msg ("Player Condition: paralyzed")
  }
}

P.S.

here's a guide on using lists and dictionaries:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk

ask if you got any questions or need help with anything


Again, I do not understand that format, hegemonkhan
I will attempt Curt A.P. 's outline for the time being...


@ CheshireTiger:


try to follow these instructions in my previous post:

http://textadventures.co.uk/forum/quest/topic/vxger3_ufkwp4hmpsie2ia/choices-after-player-takes-object-into-room#616128e8-31cf-46a1-af0b-090101f8ef24

(I'm too lazy to try 'it = my code' myself, so let me know if 'it = my code' doesn't work, lol)

(also, if you need any help/explanation with any of the instructions or whatever, let me know)


also, this is a very good guide by Pixie, explaining how to do lists/menus:

http://docs.textadventures.co.uk/quest/guides/character_creation.html

ask, if you need help with anything or got any questions about it


I ran into a problem in 'switch' and 'show menu'

As Curt A.P. explained, I put the 2 options in as such
Options from list/dictionary: [Split:("watch;play") ]
After choosing, run script:
Switch: [result ]
Cases: [watch ] print message : "TESTING WATCH"
[play ] print message ; "TESTING PLAY"
somehow this causes an error in-game.
Error compiling expression 'watch play': unknown object or variable 'watch'


K.V.

Hello.

Can you post the actual code from your game?


Hesitant
not sure if i should...it's homoerotic and any moderators might not like that stuff in their forums...


K.V.

Oh, I see.

It should look like this in code view:

ShowMenu ("Pick one.", Split ("watch;play"), false) {
  switch (result) {
    case ("watch") {
      msg ("You chose 'watch'.")
    }
    case ("play") {
      msg ("You chose 'play'.")
    }
  }
}

GUI View:

image


image


Thank you so much. didnt think i had to have them in quotations as cases


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

Support

Forums