Elmor's wml questions

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.
User avatar
artisticdude
Moderator Emeritus
Posts: 2424
Joined: December 15th, 2009, 12:37 pm
Location: Somewhere in the middle of everything

Re: Elmor's wml questions

Post by artisticdude »

Oh, you want to change terrain defenses? My apologies, I missed your earlier post.

In that case, no, I don't think you can manipulate variables to change that (although I might be wrong about that). You can use [object] and [effect] to manipulate terrain defense, like so:

Code: Select all

        [object]
        silent=yes
	  [effect]
		apply_to=defense
		replace=no
		[defense]
		deep_water=-5%
		shallow_water=-5%
		swamp_water=-5%
		reef=-5%
		flat=-5%
		sand=-5%
		forest=-5%
		hills=-5%
		mountains=-5%
		village=-5%
		castle=-5%
		cave=-5%
		frozen=-5%
		unwalkable=-5%
		impassable=-5%
		fungus=-5%
		[/defense]
	  [/effect]
        [/object]  
Note that you are actually adding defense by using negative numbers. Positive numbers will decrease defense.
"I'm never wrong. One time I thought I was wrong, but I was mistaken."
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

sorry, that code doesn`t work

look, I also want to kill unit if it`s no more another units, but it doesn`t work:

Code: Select all

    [event]
        name=new turn
        first_time_only=no
        [if]
            [not]
                [have_unit]
                    side=$side_turn
                    [not]
                        id=Leader$side_turn
                    [/not]
                [/have_unit]
            [/not]
            [then]
                [kill]
                    [filter]
                        side=$side_turn
                        id=Leader$side_turn
                    [/filter]
                [/kill]
            [/then]
        [/if]
    [/event]
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Elmor's wml questions

Post by Ceres »

1. Using a side turn event here would be much more senseful:
-> side turn event: triggers when it's another side's turn
-> new turn event: triggers when a completely new turn begins, i.e. turn number / ToD change
2.

Code: Select all

  id=Leader$side_turn
I'm not sure whether variable substitution can do that, but you could simply filter for "canrecruit=yes" instead.
3. The auto-stored variable containing the currently active side's number is named "side_number", not "side_turn".
4. Don't use [filter] in [kill].
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

thanks, it works

now, please, help me, the biggest question

I want to make all units die after number of turns, but it must be different number for different units
I mean, for example, all units must die after 10 turns, but counting from turn, each of them was placed in game separately

I was thinking about something like that:

Code: Select all

{VARIABLE "unitnumber" 0} #here unit takes number
[unit]
    {VARIABLE "unit_turns_max$unit_number" 10}
    {VARIABLE "unit_turns$unit_number" 0}
    {VARIABLE_OP "unit_number" add 1} #here counting starts for other units numbers
[/unit]
[event]
    name=new turn
        [if]
            [variable]
                name=unit_turns$unit_number
                greater_than=$unit_turns_max$unit_number
            [/variable]
        [/if]
        [then]
            ??? # I don`t know how to filter unit with needed variable value
        [/then]
[/event]
may be there is a way to dedicate variable value to unit?
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: Elmor's wml questions

Post by SlowThinker »

Elmor wrote:may be there is a way to dedicate variable value to unit?
Yes, any unit can store variables. See http://wiki.wesnoth.org/SingleUnitWML
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Elmor's wml questions

Post by Sapient »

http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

sorry, still can`t understand how to save variable inside unit
can you, please, help me understand?

must it be something like storing units? or it must be inside unit tag?

somebody?
User avatar
Elvish_Hunter
Posts: 1576
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Elmor's wml questions

Post by Elvish_Hunter »

First you need to store the unit somewhere, with the usual [store_unit] tag.
Then, you need to use [set_variable]. Let's say, for example, that you have your unit stored into the my_unit variable. You'll use

Code: Select all

[set_variable]
    name=my_unit.variables.my_var
    value=5
[/set_variable]
Then, you'll have to unstore the unit, with [unstore_unit]. Of course, if there is more than one unit stored inside your variable, you'll have to use {FOREACH} and {NEXT} as appropriate.
It is possible also to place the [variables] tag inside a [unit] tag:

Code: Select all

[unit]
    id=my_unit
    type=Yeti
    x,y=1,1
    [variables]
        my_var=5
    [/variables]
[/unit]
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

yes, I see, but I need to transform value, that contains variable, to numerical value. But for each unit it must be different value
I mean something like that

Code: Select all

[set_variable]
    name=my_unit.variables.my_var
    value=$turn_number
[/set_variable]
or this variable, since it was set, doesn`t change it`s value, despite of value`s variable value?
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Elmor's wml questions

Post by Ceres »

Store all units every turn, and then use FOREACH to iterate through all of them, modifying each one's variables.

Anyway, it would be better to not set it to the turn number, but to sub 1 every turn. Set my_unit.variables.my_var to the number of turns they should survive, using a recruit/recall/whatever event, sub 1 each turn and check whether any unit's count is 0, then kill these.
At least that's how I understood what you want to do.
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Elmor's wml questions

Post by Exasperation »

Actually, I think it would be better to set it to the turn you want them to die. Consider:

Code: Select all

[set_variable]
    name=my_unit.variables.die_on
    value="$($turn_number+5)"
[/set_variable]

Code: Select all

[event]
    name=new turn
    first_time_only=no
    [kill]
        [filter_wml]
            [variables]
                die_on=$turn_number
            [/variables]
        [/filter_wml]
    [/kill]
[event]
Saves a lot of storing/unstoring and variable modification.
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

sorry, still don`t understand
I got unit1, that advances to unit2. I need to kill all unit2 after they spend their lifespan.
I used this one inside [unit_type]:

Code: Select all

    [set_variable]
        name=my_unit.variables.die_on
        value=5
    [/set_variable]
and this one inside [multiplayer]:

Code: Select all

    [event]
        name=new turn
        first_time_only=no
        {VARIABLE_OP die_on add -1}
        [store_unit]
            [filter]
                [filter_wml]
                    [variables]
                        die_on=0
                    [/variables]
                [/filter_wml]
            [/filter]
            kill=yes
        [/store_unit]
    [/event]
How must it be for real?
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: Elmor's wml questions

Post by Crendgrim »

1. [set_variables] is not allowed inside [unit_type]. You'll need to put that in a recruit event and filter if the primary unit is of the correct unit type.
Try: (untested)

Code: Select all

[event]
  name=recruit
  first_time_only=no
  [filter]
    type=your_unit_type
  [/filter]
  [set_variable]
        name=unit.variables.die_on
        value=5
    [/set_variable]
[/event]
2. [wiki=InternalActionsWML#.5Bstore_unit.5D][store_unit][/wiki] takes a variable= key where it saves the units to. If you don't want to keep them, you can just use [wiki=DirectActionsWML#.5Bkill.5D][kill][/wiki] (be sure not to use a [filter] tag inside kill).
(again untested)

Code: Select all

[kill]
  [filter_wml]
    [variables]
      die_on=0
    [/variables]
  [/filter_wml]
[/kill]
3. You decrement only the global variable die_on, but you have to do this for every unit of your unit type. This would be easier if you followed Exasperation's suggestion.
UMC Story Images — Story images for your campaign!
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Elmor's wml questions

Post by Ceres »

I support Exasperation's method:

Code: Select all

[event]
	name=post advance
	furst_time=only=no
	[filter]
		type=(unit type after advancing)
	[/filter]
	[set_variable]
	    name=unit.variables.die_on
	    value="$($turn_number+5)"
	[/set_variable]
	[unstore_unit]
		variable=unit
		find_vacant=no
	[/unstore_unit]
[/event]
[event]
    name=new turn
    first_time_only=no
    [kill]
        [filter_wml]
            [variables]
                die_on=$turn_number
            [/variables]
        [/filter_wml]
    [/kill]
[event]
Crend: you forgot unstoring unit after variable modification :eng:
Elmor
Posts: 152
Joined: May 5th, 2010, 8:19 am

Re: Elmor's wml questions

Post by Elmor »

and if I`m not using recruit and advance, I`m using [unit] and [transform_unit]?
can I use it inside [unit]? and what to do with transforming? variable will be saved?
Post Reply