Menu change help

Id like a 4 chouce repeataboe menu to add a 5th option after the other 4 have been chosen.

Example

  1. Einie
    2 Meanie
  1. miney
  2. Moe
  3. Bazinga

Where is this menu?

I'd suggest making a stringlist attribute containing the options that have been chosen; and if the length of the list is 4, add the 5th.

Alternatively, if you're removing options after they've been chosen, you could make a list of the options to be chosen.

For example:

if (not HasAttribute (game, "options_left")) {
  game.options_left = Split("Option1;Option2;Option3;Option4")
}
else if (ListCount (game.options_left) = 0) {
  list add (game.options_left, "extra option")
}
ShowMenu ("Pick an option!", game.options_left, true) {
  list remove (game.options_left, result)
  // do other stuff here
}

I have it under an npc speak to scripts.

I was thinking more along the lines of removi g each after it is selected with the 5th apearing after the remaining one is removed....


I was thinking more along the lines of removi g each after it is selected with the 5th apearing after the remaining one is removed....

Well, I gave you a script to do that. Just change game.options_left to some attribute name that represents what it contains.


Heres what i have as the list

Kidou = NewStringList()
list add (Black Coffin, Kidou)
list add (Crashing Blue Flames, Kidou)
list add (Crawling Rope, Kidou)
list add (Arc Shield, Kidou)
if () {
}

How whoiuld i use this with your sugestion?


Hello.


It doesn't look like you're creating your list correctly.

You have it like this: list add (item, list)

It should be like this: list add (list, item).

Also, you seem to be attempting to add objects to a string list.

Based upon your post (not knowing if those things are actually objects in your game, but assuming so), you probably want to create that list like this (and note that I am just creating a new list, not a new string list):

Kidou = NewList()
list add (Kidou, Black Coffin)
list add (Kidou, Crashing Blue Flames)
list add (Kidou, Crawling Rope)
list add (Kidou, Arc Shield)

From there, if the code in your post hasn't confused me, and the list is functional, you can plug that into mrangel's code thusly:

if (not HasAttribute (game, "options_left")) {
  game.options_left = NewList()
  list add (game.options_left, Black Coffin)
  list add (game.options_left, Crashing Blue Flames)
  list add (game.options_left, Crawling Rope)
  list add (game.options_left, Arc Shield)
}
else if (ListCount (game.options_left) = 0) {
  list add (game.options_left, Put_Fifth_Object_Name_Here)
  //NOTE: Replace "Put_Fifth_Object_Name_Here" in the line above with your actual fifth object's name!
}
ShowMenu ("Pick an option!", game.options_left, true) {
  list remove (game.options_left, result)
  // do other stuff here
}

REFERENCE

https://docs.textadventures.co.uk/quest/scripts/list_add.html

list add

list add (list, any type item)

Adds an item to a list.

See Using Lists


No it seems to work as a menu list fine as it is. Isnt that how its suposed to work as a string list?

The names are the options, not ingane objects.

Il try as you sugested, K.V.

So whould i have to make an atribute called options_left?


No it seems to work as a menu list fine as it is.

What seems to work as a menu list fine as it is?

Can you post the code you have that works?


Isnt that how its suposed to work as a string list?

First off, the code you posted here has errors. So, I have no clue what code you have that you say seems to work.

Second, if I create a new string list, then try to add objects to it (as you have in your last example, except you have the list add bits with their parameters backwards and I don't have those errors in my test code), Quest throws this error:

Error running script: Unable to cast object of type 'TextAdventures.Quest.Element' to type 'System.String'.


If, however, I create a new list like I posted in my last example (which I mostly copied from mrangel's example), it works properly.


So whould i have to make an atribute called options_left?

That is done in the code I posted (which I mostly copied from mrangel's example).

This line does that: game.options_left = NewList()


To elaborate on the list type issue, you have this:

Kidou = NewStringList()
list add (Black Coffin, Kidou)
list add (Crashing Blue Flames, Kidou)
list add (Crawling Rope, Kidou)

As I pointed out already, your list add parameters are backwards. So, let's fix those first:

Kidou = NewStringList()
list add (Kidou, Black Coffin)
list add (Kidou, Crashing Blue Flames)
list add (Kidou, Crawling Rope)

Now, if you try to run that code, it should throw this error: Error running script: Unable to cast object of type 'TextAdventures.Quest.Element' to type 'System.String'.

This is because that code tries to add an object (aka 'TextAdventures.Quest.Element') to a string list (aka 'System.String').

To fix that issue, let's change the first line to simply create a list with no specified type:

Kidou = NewList()
list add (Kidou, Black Coffin)
list add (Kidou, Crashing Blue Flames)
list add (Kidou, Crawling Rope)

ALTERNATIVELY, if you just want to create a string list (even though ShowMenu() can easily handle the object list just as easily), you could change it to this:

Kidou = NewStringList()
list add (Kidou, "Black Coffin")
list add (Kidou, "Crashing Blue Flames")
list add (Kidou, "Crawling Rope")

OR

Kidou = NewStringList()
list add (Kidou, Black Coffin.name)
list add (Kidou, Crashing Blue Flames.name)
list add (Kidou, Crawling Rope.name)

Also, I'm going to bow out of this thread now.

I am only adding confusion, and mrangel is better at this stuff than I am anyway. Plus, I kind of butted in after he'd already started helping out, anyway. :)


Good luck, and happy gaming!


Kidou = NewStringList()
list add (Black Coffin, Kidou)
list add (Crashing Blue Flames, Kidou)
list add (Crawling Rope, Kidou)
list add (Arc Shield, Kidou)

I think you might have made a mistake when copying it to the forum, as this won't do anything helpful.
It assumes that Black Coffin, Crashing Blue Flames, Crawling Rope, and Arc Shield are all local variables containing lists. If they aren't it will cause an error. If they are, it will create a new list named Kidou and add that to the end of all the others.

If Black Coffin, Crashing Blue Flames, Crawling Rope, and Arc Shield are the names of in-game objects, then as KV says your code would need to be:

Kidou = NewObjectList()
list add (Kidou, Black Coffin)
list add (Kidou, Crashing Blue Flames)
list add (Kidou, Crawling Rope)
list add (Kidou, Arc Shield)

if they are just menu options, it would need to be:

Kidou = NewStringList()
list add (Kidou, "Black Coffin")
list add (Kidou, "Crashing Blue Flames")
list add (Kidou, "Crawling Rope")
list add (Kidou, "Arc Shield")

which is an unusual thing to do because it's exactly the same as:

Kidou = Split ("Black Coffin;Crashing Blue Flames;Crawling Rope;Arc Shield")

In which case the full code to display the menu would be:

if (not HasAttribute (game, "kidou")) {
  game.kidou = Split ("Black Coffin;Crashing Blue Flames;Crawling Rope;Arc Shield")
}
else if (ListCount (game.kidou) = 0) {
  list add (game.kidou, "Ultimate Final Option")
}
ShowMenu ("Pick an option!", game.kidou, true) {
  list remove (game.kidou, result)
  switch (result) {
    case ("Black Coffin") {
      // insert code here
    }
    case ("Crashing Blue Flames") {
      // insert code here
    }
    case ("Crawling Rope") {
      // insert code here
    }
    case ("Arc Shield") {
      // insert code here
    }
    case ("Ultimate Final Option") {
      // insert code here
    }
  }
}

if they are just menu options, it would need to be:

Kidou = NewStringList()
list add (Kidou, "Black Coffin")
list add (Kidou, "Crashing Blue Flames")
list add (Kidou, "Crawling Rope")
list add (Kidou, "Arc Shield")

That causes internal error. As does it withoit the ""

Nevermind. Just fixed that part


So it should be

list remove (Kidou, "Black Coffin")

Ect...yes?


So it should be

list remove (Kidou, "Black Coffin")

Ect...yes?

Where would you put that?

If you're making a local variable like Kidou, it only exists until the end of the function.
That's why I suggested making an attribute game.kidou, adding all the items to it, and removing them when they are chosen.

You will notice that in the script I gave you, it uses:

list remove (game.kidou, result)

This is the only 'remove' line you need.


After a mgs the option is chosen from the menu.

  switch (result) {
    case ("Black Coffin") {
      msg
      Remove code here
      }

"Local attribute"?


After a mgs the option is chosen from the menu.

Do you only want it to remove some of the options and not others?
Or is there some condition which decides if the option should be removed or not?

Using the situation you originally described, there is no reason to move the remove code there.

Code inside the switch/case structure is for things that depend which option the player chose.

If you want to "remove the option the player chose" no matter which option it is, you do that before the switch.

"Local attribute"?

What's that?

Variables are local in Quest. Attributes are not.

There is no such thing as a local attribute.

In your code, you had Kidou = NewStringList().

That creates a local variable called Kidou. Because it is a local variable, it disappears as soon as the script/function/verb ends.
If you want to use it to keep track of which options the player has chosen, you need it to stick around.

That's why I changed it to game.kidou. That is an attribute kidou for the game element. It keeps the same value as long as game exists.

So you can make it a list of options, and then next turn you remove the one that the player chose from it.

Does that make sense?


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

Support

Forums