Filter selected unit?

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Smok
Posts: 50
Joined: June 14th, 2016, 11:52 am

Filter selected unit?

Post by Smok » May 11th, 2017, 5:23 pm

How can i filter unit with is actually selected by player?

gfgtdf
Developer
Posts: 982
Joined: February 10th, 2013, 2:25 pm

Re: Filter selected unit?

Post by gfgtdf » May 11th, 2017, 5:34 pm

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.

User avatar
beetlenaut
Developer
Posts: 2169
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Filter selected unit?

Post by beetlenaut » May 11th, 2017, 5:51 pm

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

User avatar
Sapient
Developer
Posts: 4429
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Filter selected unit?

Post by Sapient » May 11th, 2017, 6:34 pm

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."

gfgtdf
Developer
Posts: 982
Joined: February 10th, 2013, 2:25 pm

Re: Filter selected unit?

Post by gfgtdf » May 11th, 2017, 6:53 pm

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.

Smok
Posts: 50
Joined: June 14th, 2016, 11:52 am

Re: Filter selected unit?

Post by Smok » May 11th, 2017, 11:28 pm

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.
Last edited by Smok on May 12th, 2017, 12:51 am, edited 2 times in total.

User avatar
beetlenaut
Developer
Posts: 2169
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Filter selected unit?

Post by beetlenaut » May 11th, 2017, 11:44 pm

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

Smok
Posts: 50
Joined: June 14th, 2016, 11:52 am

Re: Filter selected unit?

Post by Smok » May 12th, 2017, 12:10 am

beetlenaut wrote:it sounds like the right-click menu will need to be activated on a unit
Nope.

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).

User avatar
Sapient
Developer
Posts: 4429
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Filter selected unit?

Post by Sapient » May 12th, 2017, 1:28 am

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.
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
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Filter selected unit?

Post by LordAndrew » April 3rd, 2018, 4:48 pm

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]

Post Reply