menu items

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
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

menu items

Post by inuyasha35 »

I have not yet found a way to create menu items, I even tried copying them from eighteenth century warfare but to no succsess, the specific thing I am trying to do is make a unit that can summon another unit, I did that once before but the trigger was the attack "Deploy robots" could somebody please send me an example of a menu item and explain it. thank you in advance
User avatar
Pentarctagon
Project Manager
Posts: 4537
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: menu items

Post by Pentarctagon »

Moved to the WML Workshop.

What you're looking for generally though is [set_menu_item].
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

could I have an example of a menu item?
User avatar
GForce0
Posts: 40
Joined: May 17th, 2020, 5:58 pm

Re: menu items

Post by GForce0 »

I can give you this example from one of my scenario's where you can build a ship. Which is similar to what you want to do: summoning a unit. Just change the boat to a unit in your case. I will explain below the code

Code: Select all

[set_menu_item]
	id = build_ship
	description= _ "Build ship"
	
	[show_if]
		[not]
			[have_unit]
				x,y = $x1,$y1
			[/have_unit]
		[/not]
	[/show_if]

	[filter_location]
		terrain = Ww
		[filter_adjacent_location]
			terrain = C*
			[filter]
				canrecruit = yes
				side = $side_number
			[/filter]
		[/filter_adjacent_location]
	[/filter_location]

	[command]
		[store_gold]
			side = $side_number
			variable = gold
		[/store_gold]

		[if]
			[variable]
				name = gold
				greater_than_equal_to = $boat_cost
			[/variable]
			[then]
				[unit]
					type = Galleon
					x,y = $x1, $y1
					side = $side_number
					moves = 0
				[/unit]
				[set_variable]
					name = gold
					sub = $boat_cost
				[/set_variable]
				[modify_side]
					side = $side_number
					gold = $gold
				[/modify_side]
			[/then]
			[else]
				[message]
					side_for = $side_number
					speaker = narrator
					message = _"You need at least $boat_cost gold to build a ship"
				[/message]
			[/else]
		[/if]	
	[/command]
[/set_menu_item]

You put this entire part inside the prestart event.

- Description is the text that you will see in the right-click menu.

- [show_if]
This tells when the menu item should appear in the menu. In my case, I want it to only appear if there is no unit on the hex that I am right-clicking.
$x1, $y1 contain the coordinates of the hex where you right-clicked

- [filter_location]
An additional condition where the item should appear in the right-click menu and where not.
First, I say it must only appear right-clicking on hexes that are shallow water: terrain = Ww. (Because we're dealing with boats)
Then also, below that it says that there should be your leader standing next to the hex that you right-clicked, and where the leader is standing it must be a castle hex.
(To be strict, it actually says there must be a castle hex next to the hex that you right-clicked, and on that castle hex there must be your leader)

- [command]
Inside the command tags, you specify what will happen after you click the menu item.
Assuming that you know basic WML, I suppose you can figure out what it does.
Otherwise let me know what is not clear, then I can explain in more detail.
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

the code you sent me didn't work :( .I think it might just be a problem with my computer OR my text editor, I use text wrangler on a macbook air.

ps. I have the latest version.
Last edited by WhiteWolf on September 24th, 2020, 10:06 pm, edited 1 time in total.
Reason: doublepost merged
User avatar
WhiteWolf
Forum Moderator
Posts: 655
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: menu items

Post by WhiteWolf »

inuyasha35 wrote: September 24th, 2020, 9:20 pm I think it might just be a problem with my computer OR my text editor
Any UTF-8 text editor can do this job, that's the only requirement, so I doubt that your text editor is the problem. By "didn't work", do you mean that it prevents the scenario from loading with an error message (which then clearly says what has to be fixed), or just that the menu item didn't appear at all?

One possible error I can think if is the placement of your code: [set_menu_item] is an interface action, therefore goes inside an [event], a prestart event is most commonly used for this application.
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

the menu item simply does not appear.
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

is there any problem with macbook airs that could be interfereing?
User avatar
Pentarctagon
Project Manager
Posts: 4537
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: menu items

Post by Pentarctagon »

It might be best if you posted the code you have written so far.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
GForce0
Posts: 40
Joined: May 17th, 2020, 5:58 pm

Re: menu items

Post by GForce0 »

Are you right-clicking on shallow water? With a leader on a castle (not keep) next to it?

You could also remove the [show_if] and [filter_location] parts as a start. Then it will appear everywhere
User avatar
beetlenaut
Developer
Posts: 2499
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: menu items

Post by beetlenaut »

inuyasha35 wrote: September 25th, 2020, 12:58 am is there any problem with macbook airs that could be interfereing?
It's definitely not the computer, and since the scenario is loading fine, it can't be the text editor either. I'm sorry to say it, but it's the code. (In my experience, it's always the code!) It could be something really small though, so for the fastest help, you should zip it up and post the whole thing like Pentarctagon suggested. Otherwise, we are just guessing.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

one note I have is, I did some coding by directly editing the code instead of doing it in an add-ons folder, could it be possible that is interfereing?
User avatar
Pentarctagon
Project Manager
Posts: 4537
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: menu items

Post by Pentarctagon »

Yep. You should never ever be modifying the core files you get from downloading the game unless you're sure you know what you're doing. And even then it's still probably a bad idea.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
inuyasha35
Posts: 27
Joined: September 24th, 2020, 2:57 am

Re: menu items

Post by inuyasha35 »

I reset my wesnoth account to it's original settings and it works now. thanks
Post Reply