menu items
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.
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
menu items
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
- Pentarctagon
- Project Manager
- Posts: 5586
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: menu items
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
could I have an example of a menu item?
Re: menu items
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
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.
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.
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
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.
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
Reason: doublepost merged
Re: menu items
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?inuyasha35 wrote: ↑September 24th, 2020, 9:20 pm I think it might just be a problem with my computer OR my text editor
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.Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
the menu item simply does not appear.
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
is there any problem with macbook airs that could be interfereing?
- Pentarctagon
- Project Manager
- Posts: 5586
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: menu items
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
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: menu items
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
You could also remove the [show_if] and [filter_location] parts as a start. Then it will appear everywhere
- beetlenaut
- Developer
- Posts: 2828
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: menu items
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.inuyasha35 wrote: ↑September 25th, 2020, 12:58 am is there any problem with macbook airs that could be interfereing?
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
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?
- Pentarctagon
- Project Manager
- Posts: 5586
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: menu items
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
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Posts: 32
- Joined: September 24th, 2020, 2:57 am
Re: menu items
I reset my wesnoth account to it's original settings and it works now. thanks