Listbox menu in a Campaign? (Split & Option)

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
SigurdFireDragon
Developer
Posts: 501
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Listbox menu in a Campaign? (Split & Option)

Post by SigurdFireDragon »

Is there a way to do a listbox menu in a campaign to present choices to the player, like how a multiplayer scenario uses one to let you chose a faction?

I'd rather not use bunches of [message] & [option]s if avoidable.
Last edited by SigurdFireDragon on January 20th, 2011, 3:36 am, edited 1 time in total.
Maintainer of Wings of Valor
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
User avatar
Natasiel
Moderator Emeritus
Posts: 60
Joined: February 28th, 2007, 7:43 pm

Re: Listbox menu in a Campaign?

Post by Natasiel »

"Bunches of [message] & [option]s" is the way to go. If you think it results in ugly code, you can fancy yourself with some custom made macros.
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Listbox menu in a Campaign?

Post by Anonymissimus »

Other than that there are the dialog functions in lua. And other than that you could use [message]+[option] in lua like it's done in Settlers of Wesnoth which eases the thing considerably too.
This is a lot more difficult than wml+[message]+[option]s however (unless you know lua).

EDIT
Considering the date you registered your account I suggest starting by trying to get a simple yes/no choice to get displayed using wml. There should be many examples in MP scenarios.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
SigurdFireDragon
Developer
Posts: 501
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: Listbox menu in a Campaign?

Post by SigurdFireDragon »

Lol had done that & a text_input before I started the thread. I'm picking it up fast :)

Mostly now I'm annoyed at how many places I'd like to use Conditionals, but can't

I've got about 9 pages of 4-8 options each to code, was hoping I could get around writing them all out.

Instead of a list box would like to have done a [do]-[while] inside a [message] to read a list & make the corresponding [option]s for each page, but from what I understand of the ReferenceWML pages & testing that won't work. Is this correct?
Maintainer of Wings of Valor
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Listbox menu in a Campaign?

Post by Sapient »

There are several ways to dynamically control message options.

One way is to use [show_if] to prevent an option from displaying unless certain conditions are met.

Another way is to construct an option array in a variable and insert it dynamically using [insert_tag].

It's hard to give any more specific advice without knowing more details.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SigurdFireDragon
Developer
Posts: 501
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: Listbox menu in a Campaign?

Post by SigurdFireDragon »

Thanks everyone, with your help it finally clicked how I can get those 9 pages of 4-8 options each written automatically when needed.
Here's the code I went with:

Code: Select all

[a Switch sets contents of Text_List]

[set_variables]
name=Text_Array
[split]
	list=$Text_List
	key=x
	separator=,
	remove_empty=no
[/split]
[/set_variables]

[message]
	speaker=narrator
	message=_"Make your choice:"
	[option]
		[show_if]
			[variable]
				name=Text_Array[0].x
				not_equals=""
			[/variable]
		[/show_if]
		message="$Text_Array[0].x"
		[command]
			{VARIABLE Choice $Text_Array[0].x}
		[/command]
	[/option]
	[10 more options like the above for Text_Array[x].x]
[/message]
Thus a list is spilt automatically, & unused options are not shown.
Thanks again :)
Maintainer of Wings of Valor
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Listbox menu in a Campaign?

Post by Sapient »

For your reference, here's how to do it with insert_tag...

Code: Select all

# a Switch sets contents of Text_List

[set_variables]
name=Text_Array
[split]
	list=$Text_List
	key=message
	separator=,
	remove_empty=no
[/split]
[/set_variables]

{FOREACH Text_Array i}
	[set_variables]
		name=Text_Array[$i].command
		[value]
			{VARIABLE Choice $Text_Array[$i].message}
		[/value]
	[/set_variables]
{NEXT i}

[message]
	speaker=narrator
	message=_"Make your choice:"
	[insert_tag]
		name=option
		variable=Text_Array
	[/insert_tag]
[/message]
However, I see two problems:
1) commas are too common in messages to use as a general purpose separator
2) storing a translated value as a return value could cause a problem (it must be translated the same way in both places, both when creating the list and when checking its result)... better to return an index
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Natasiel
Moderator Emeritus
Posts: 60
Joined: February 28th, 2007, 7:43 pm

Re: Listbox menu in a Campaign?

Post by Natasiel »

Then, [insert_tag] might be formidable for redundancy, say across menu levels.
SigurdFireDragon
Developer
Posts: 501
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: Listbox menu in a Campaign? (Split & Option)

Post by SigurdFireDragon »

Thanks for posting that Sapient, would have taken forever for me to figure out the nuances in using split, insert_tag & option on my own.
Maintainer of Wings of Valor
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Post Reply