3 questions: to_location; chaining events ; store_unit

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
Helmet
Posts: 331
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

3 questions: to_location; chaining events ; store_unit

Post by Helmet »

I've been reading the Wiki...

Apparently an x,y location can receive an id? And there is a filter attribute called location_id that filters that id? And a unit can be sent there via [move_unit] and to_location?

So...if I'm understanding correctly, instead of moving a unit to a specific snow terrain via the terrain's x,y location, I could move the unit to a place I had id-named patch_of_snow?

If that's right, can I get an example from someone? Thanks.

That was my main question, but here are two more.

2nd question: how do you use a + to chain an event to the event above it? I've seen it here and there, but I can't find it on the Wiki. Are there any special rules I should be aware of?

3rd question: Is this how you would check if a unit is poisoned? It works, but maybe there's a better, simpler way?

Code: Select all

[store_unit] #								CURE POISON
	[filter]
		id=MyLeader # 						this will store MyLeader in an array
	[/filter]
	variable=myleader_data
[/store_unit]	
[if]
	[variable]
		name=myleader_data.status.poisoned #			if this unit is poisoned...
		equals=yes
	[/variable]
	[then]
#   message about poison, cure poison, etc.	
Thanks.
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: 3 questions: to_location; chaining events ; store_unit

Post by WhiteWolf »

Moved to WML Workshop.

Someone more experienced with 1.15 features can hopefully answer your main question, but based on the wiki, what you said sounds correct and should work like that.
Helmet wrote: December 29th, 2020, 4:19 pm 2nd question: how do you use a + to chain an event to the event above it? I've seen it here and there, but I can't find it on the Wiki. Are there any special rules I should be aware of?

Code: Select all

[event]
stuff
[/event]

stuff that doesn't contain events

[+event]
you're now continuing the event tag that ended with stuff
[/event]
No special rules that I'm aware of, but keep in mind that it can only append to the most recent tag before it. That's why I wrote "stuff that doesn't contain events" in the middle part.
3rd question: Is this how you would check if a unit is poisoned? It works, but maybe there's a better, simpler way?

Code: Select all

[if]
    [have_unit]
        id=MyLeader
        status=poisoned
    [/have_unit]
    [then]
Author of 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
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
beetlenaut
Developer
Posts: 2535
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: 3 questions: to_location; chaining events ; store_unit

Post by beetlenaut »

Helmet wrote: December 29th, 2020, 4:19 pm If that's right, can I get an example from someone? Thanks.
You explained it right, so I assume you mean an example of how to create a location id. They are created in the map editor. Choose the "Starting Positions Tool" (the little flag). You will get a list of sides with some buttons at the bottom of the list. Select the "Add" button to add a location to the list and name it. Use the tool to place that named location where you want.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 331
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: 3 questions: to_location; chaining events ; store_unit

Post by Helmet »

WhiteWolf wrote: December 29th, 2020, 4:30 pm No special rules that I'm aware of, but keep in mind that it can only append to the most recent tag before it. That's why I wrote "stuff that doesn't contain events" in the middle part.
Thank you. I thought it would be a good idea to link events like this... (I was afraid maybe they would not fire in the right order, otherwise).

Code: Select all

[event]
	name=turn 2
[/event]

# stuff

[event]
	name=turn 2
[/event]
WhiteWolf wrote: December 29th, 2020, 4:30 pm

Code: Select all

[if]
    [have_unit]
        id=MyLeader
        status=poisoned
    [/have_unit]
    [then]
I had a suspicion there was a better way. Thanks.
beetlenaut wrote: December 29th, 2020, 5:00 pm
Helmet wrote: December 29th, 2020, 4:19 pm If that's right, can I get an example from someone? Thanks.
You explained it right, so I assume you mean an example of how to create a location id. They are created in the map editor. Choose the "Starting Positions Tool" (the little flag). You will get a list of sides with some buttons at the bottom of the list. Select the "Add" button to add a location to the list and name it. Use the tool to place that named location where you want.
Thanks. I guess I was hoping there would be a way to do it all in a text editor. I used to be able to open my maps in TextWrangler and edit the code (Gg, etc.). Recently, something changed. Now I can only open old maps in TextWrangler. New maps won't open. So I'm a little more worried about corrupting a map than I used to be. (I sometimes corrupt maps when experimenting with terrain graphics, and I have to manually erase my failures.)

Anyhow, thanks, beetlenaut. I didn't realize that the flag in the Map Editor had an ADD function. Problem solved.
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: 3 questions: to_location; chaining events ; store_unit

Post by WhiteWolf »

Helmet wrote: December 29th, 2020, 6:18 pm I thought it would be a good idea to link events like this... (I was afraid maybe they would not fire in the right order, otherwise).
I don't think there's a single "correct" way, it entirely depends on what you want to achieve exactly. :) The +tag way appends the previous matching tag, and this code you posed just has two different events for turn 2.
Author of 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
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
GForce0
Posts: 63
Joined: May 17th, 2020, 5:58 pm

Re: 3 questions: to_location; chaining events ; store_unit

Post by GForce0 »

why would you use the +tag and not put it in the same event?
User avatar
Helmet
Posts: 331
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: 3 questions: to_location; chaining events ; store_unit

Post by Helmet »

GForce0 wrote: December 30th, 2020, 9:12 am why would you use the +tag and not put it in the same event?
Mostly because there are two IF/THEN blocks happening in the same turn, and they do different things, so I thought separating them would work better. And the other reason is that I thought it would make my code appear tidy.

Code: Select all

[event]
	name=side 1 turn end
	first_time_only=no
	[filter]
		id=MyLeader
		x,y=8,8
	[/filter]		
	[store_unit]
		[filter]
			id=MyLeader
		[/filter]
		variable=myleader_data 
	[/store_unit]
	[if]
		[then]
			###
		[/then]
	[/if]
[/event]

[+event]
	name=side 1 turn end
	first_time_only=no
	[filter]
		side=1
		can_recruit=yes
		x,y=3,3
	[/filter]		
	[if]
		[have_unit]
			x,y=3,3
			id=MyLeader	
		[/have_unit]
		[then]
			###
		[/then]
	[/if]
[/event]
Does the +tag work with events that have multiple names? Like name=turn 2,moveto? Do all the names have to match? Or can just one match?
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: 3 questions: to_location; chaining events ; store_unit

Post by WhiteWolf »

But this is not how the + syntax is supposed to be used. It doesn't "link" tags as you previously put it - it appends to the end of it. So

Code: Select all

    stuff
[/tag]
[+tag]
   other stuff
[/tag]
Is equivalent to

Code: Select all

   stuff
   other stuff
[/tag]
Therefore this question:
Does the +tag work with events that have multiple names? Like name=turn 2,moveto? Do all the names have to match? Or can just one match?
doesn't make much sense. What is there to match? You're just expanding the end of the event with more stuff.
Cutting out the action wml part for visibility, your posted code is currently equivalent to this:

Code: Select all

[event]
    name=turn 1 end
    [filter]
        stuff
    [/filter]
    
    action WML
    
    name=turn 1 end   # but this doesn't make sense here. A second name key? Even if it matches the previous one, this just replaces the previous key's value, rendering that one useless (with the +tag syntax, this is the behavior).
    [filter]    # a second filter, after actions already took place? Same applies.
        other stuff
    [/filter]
     other actions
[/event]
I'm surprised it runs without producing warnings in the logs, because the second name, and second filter at the middle of the event are quite in the wrong place :D

Btw, I too am wondering about why you want to do it like this, this is not a place where the + syntax is useful. If you want an example where it is indeed very useful, it's event implemented abilities definitions:

Code: Select all

#define ABILITY_1
    [dummy]
        some descriptions
    [/dummy]
[/abilities]  # you're exiting the unit's abilities tag

[event]  # this event is getting into [unit_type] now, which means it's present if the unit is present on the map
 implement your ability
[/event]

[+abilities]  # this now allows you return to the abilities tag of the unit
#enddef
Defining it this way, you can stack abilities in the [unit_type] (or anywhere else) just fine, and the events will get implemented with the unit properly:

Code: Select all

[unit_type]
    [abilities]
        {ABILITY_1}
        {ABILITY_2}
        {ABILITY_3}
        ...
    [/abilities]
[/unit_type]
Author of 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
Standalone works: The Ravagers - now for 1.14, with new bugs!
vghetto
Posts: 355
Joined: November 2nd, 2019, 5:12 pm

Re: 3 questions: to_location; chaining events ; store_unit

Post by vghetto »

Helmet wrote: December 30th, 2020, 1:50 pm And the other reason is that I thought it would make my code appear tidy.
It does not. It makes it more difficult for you or others to maintain in the future.
You don't have to use every feature of WML in your code. Try to stick to the KISS rule.

A case in point where appending events gave headaches.
https://forums.wesnoth.org/viewtopic.ph ... 88#p660888
User avatar
Ravana
Forum Moderator
Posts: 2482
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: 3 questions: to_location; chaining events ; store_unit

Post by Ravana »

I am quite sure you can put [filter] anywhere in [event] toplevel, it is just convention to have it near top.

There is no reason to use [+event]. The reason +tag is used at all is as workaround for macro limitations. For example https://github.com/ProditorMagnus/Agele ... no_zoc.cfg to add ability with macro which needs to add attribute to unit type level.
User avatar
Helmet
Posts: 331
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: 3 questions: to_location; chaining events ; store_unit

Post by Helmet »

Oh my goodness. I totally did not understand the +tag.

I thought...

Well, never mind what I thought. Thanks for explaining what the tag is for and not for.

I rewrote my events. The +tags are gone. :oops:

I finished coding my campaign today. I wonder how much of my code is not exactly logical and proper? It all seems to work, though.

I'll be uploading it in the next few days, after another round of playtesting. If you download it, you probably shouldn't look at the code. You might be afflicted with apoplexy.
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: 3 questions: to_location; chaining events ; store_unit

Post by WhiteWolf »

No worries, trial and error is probably the best way to learn :)
I wonder how much of my code is not exactly logical and proper? It all seems to work, though.
You may not realize that now, but this is actually a very good approach.
You can always optimize your code later.
It's a good mindset to first write functioning code, no matter how ugly / inefficient / badly optimized it may be, the point is that is should function as expected. Once that's done, you have all the time you want to dedicate to the project to optimize it.
Premature optimizations to a buggy or non-functioning code is a spawn hive for all kinds of other issues bugs and headaches. So always write working code first, and optimize later :)
Author of 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
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Helmet
Posts: 331
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: 3 questions: to_location; chaining events ; store_unit

Post by Helmet »

WhiteWolf wrote: December 31st, 2020, 11:41 am No worries, trial and error is probably the best way to learn :)
I wonder how much of my code is not exactly logical and proper? It all seems to work, though.
You may not realize that now, but this is actually a very good approach.
You can always optimize your code later.
It's a good mindset to first write functioning code, no matter how ugly / inefficient / badly optimized it may be, the point is that is should function as expected. Once that's done, you have all the time you want to dedicate to the project to optimize it.
Premature optimizations to a buggy or non-functioning code is a spawn hive for all kinds of other issues bugs and headaches. So always write working code first, and optimize later :)
Thanks for the words of encouragement. ^_^

Say, slightly (yet completely) different question. I now know how to use have_unit to filter by a unit's poison status, etc. Is it possible to use have_unit to filter based on a unit's level? I need something to happen if a unit is below level 2. The following code works, but if have_unit would work also, I would like to use it.

Code: Select all

		[store_unit]
			[filter]
				id=Moho
			[/filter]
			variable=moho_data
		[/store_unit]
		
	[if]
  		[variable]
			name=moho_data.level
			less_than=2
		[/variable]	
		[then]
I know this is wrong, but I don't know how to combine those 3 lines into 2 lines.

Code: Select all

[have_unit]
	id=Moho
	$this_unit.level
	less_than=2	
[/have_unit]
If it's not possible, could [or] be used with have_unit to test for level=0 or level=1?
User avatar
beetlenaut
Developer
Posts: 2535
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: 3 questions: to_location; chaining events ; store_unit

Post by beetlenaut »

[have_unit] is just a standard unit filter when it's used inside an [if] tag. (So it works the same as [filter] in an event.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: 3 questions: to_location; chaining events ; store_unit

Post by WhiteWolf »

As beetlenaut says, so the standard unit filter keys are recognized. There is a level key, but I don't know if would accept a comma separated list of level=0,1. (You could test it so that the wiki can be amended with the result info).

Otherwise you could just use a formula for this.

Code: Select all

[have_unit]
    id=Moho
    formula="level < 2"
[/have_unit]
Author of 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
Standalone works: The Ravagers - now for 1.14, with new bugs!
Post Reply