[SOLVED] Set remaining movement to 0

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
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

[SOLVED] Set remaining movement to 0

Post by Anagkai »

What I want to do is to end a unit's turn (i.e. set movement to 0) when a certain event is triggered. This should be analogous to what happens when capturing a village, except that no villages are involved. Is there an easier way to do this than using modify_unit or changing the movement points on stored_unit?
Last edited by Anagkai on September 16th, 2018, 1:51 pm, edited 1 time in total.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
Shiki
Developer
Posts: 348
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Set remaining movement to 0

Post by Shiki »

No, not really. Depending on what type of event you use, you may already have a predefined unit variable in reach and can use [unstore_unit] with it instead.

Code: Select all

[event]
  name=enter hex
  first_time_only=no
  [filter]
    x=23,24
    y=40,40
    radius=1
  [/filter]

  {VARIABLE $unit.moves 0}
  #{VARIABLE $unit.attacks_left 0} although, this is not done when capturing

  [unstore_unit]
    variable=unit
    find_vacant=no # default value
  [/unstore_unit]
[/event]
If that is too much code, you can put it into a macro.
Another idea is to have an enemy unit with ambush next to that hex.
Try out the dark board theme.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Set remaining movement to 0

Post by gfgtdf »

the only way in wml to change unit attribute is via store+unstore, if you use lua though you can modify unit attributed directly, ut lua events do have te disadvantage of less easy to use filter and no automatic undoing prevention, the lua code equivalent to shikis event

Code: Select all

on_event("enter_hex", function(cx)
  local u = wesnoth.get_unit(cx.unit_x, cx.unit_y)
  if u and u:matches( x="23,24", y="40,40") then
    u.moves = 0
    wesnoth.allow_undo(false)
  end
end)
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
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Set remaining movement to 0

Post by zookeeper »

Shiki wrote: September 13th, 2018, 3:53 pm

Code: Select all

  {VARIABLE $unit.moves 0}
Except that should be:

Code: Select all

  {VARIABLE unit.moves 0}
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: Set remaining movement to 0

Post by Anagkai »

How would I get the appropriate unit? I tried the following, which doesn't seem to work.

Code: Select all

		[store_unit]
			[filter]
				id=$unit
			[/filter]
			variable=st_unit
		[/store_unit]
		[set_variable]
			name=st_unit.moves
			value=0
		[/set_variable]
		[unstore_unit]
			variable=st_unit
		[/unstore_unit]
This happens inside a moveto event and should set the movement of the unit concerned to 0.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Set remaining movement to 0

Post by Ravana »

$unit is container variable that includes all data you need to recreate that unit. For id you want $unit.id.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Set remaining movement to 0

Post by zookeeper »

And in this case you don't even need to store the unit yourself; in events with a primary unit (such as enter_hex etc) you have the auto-stored $unit variable/container available, so something as simple as this would do:

Code: Select all

		[set_variable]
			name=unit.moves
			value=0
		[/set_variable]
		[unstore_unit]
			variable=unit
		[/unstore_unit]
Post Reply