Filter selected unit?
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.
Filter selected unit?
How can i filter unit with is actually selected by player?
Re: Filter selected unit?
note that filtering on the selected unit os potentially unsafe and can casue OOS since other players might have a different unit selected. so you probably have to use wesnoth.sync_choice or another sync function.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- beetlenaut
- Developer
- Posts: 2814
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Filter selected unit?
The way to do it is with a
name=select
event. The selected unit will be automatically stored in the unit
variable. It doesn't cause any complications in single player mode if that's where you are using it.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
Re: Filter selected unit?
It might help if you gave more information about what you are trying to achieve. For example, maybe a [set_menu_item] could work. Or maybe an unsynchronized select event would be sufficient. It all depends.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: Filter selected unit?
beetlenaut wrote: It doesn't cause any complications in single player mode if that's where you are using it.
well it might create invalid replays.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: Filter selected unit?
I want to give unit ability (used with [set_menu_item]'s item) that have X hex range. I wanted to filter unit selected by current player and from that unit position filter in X range filter positions where this ability can be used and modify this unit later. It is for multiplayer btw.
I think I could use select event and store this unit's id into variable using synchonized choices, then just filter unit with same id as variable.
I think I could use select event and store this unit's id into variable using synchonized choices, then just filter unit with same id as variable.
Last edited by Smok on May 12th, 2017, 12:51 am, edited 2 times in total.
- beetlenaut
- Developer
- Posts: 2814
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Filter selected unit?
This description of what you are doing is not clear to me, but it sounds like the right-click menu will need to be activated on a unit, and you need to know what unit was clicked. That's easy because the [command] of the right-click menu item has $x1 and $y1 available. They store the hex that was clicked. "X range" might mean the max_moves of the unit at x1, y1. The rest of it I can't figure out.
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
Re: Filter selected unit?
Nope.beetlenaut wrote:it sounds like the right-click menu will need to be activated on a unit
Lets sey, I have unit "commander" with special ability = "orbital strike". It can be used (from right clikck menu) on terrain max 2 moves from "commander" position. Additionaly this menu option will only show up if "commander" is selected, to make sure with unit player want to fire this ability (if he have few units with this ability).
Re: Filter selected unit?
In a select event, you will save the id of the commander unit at x1,y1 to a variable such as selected_unit_id. Inside the menu item command, you will have access to this variable for filtering purposes.
For wesnoth 1.12, in your [set_menu_item], use needs_select=yes (this has a few edge cases where it won't work properly, but usually it's fine).
For wesnoth 1.13, you will need to use [sync_variable] inside the [command] to synchronize the selected_unit_id variable.
For wesnoth 1.12, in your [set_menu_item], use needs_select=yes (this has a few edge cases where it won't work properly, but usually it's fine).
For wesnoth 1.13, you will need to use [sync_variable] inside the [command] to synchronize the selected_unit_id variable.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- LordAndrew
- Posts: 23
- Joined: April 1st, 2018, 3:09 am
- Location: Russia
Re: Filter selected unit?
maybe this help you
Code: Select all
[have_unit]
x,y=$x1,$y1
side=$side_number
[filter_side]
side=$side_number
[/filter_side]
[/have_unit]
Code: Select all
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=myunit
[/store_unit]