3 questions: to_location; chaining events ; store_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.
3 questions: to_location; chaining events ; store_unit
I've been reading the Wiki...
Apparently an x,y location can receive an id? And there is a filter attribute called
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
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
3rd question: Is this how you would check if a unit is poisoned? It works, but maybe there's a better, simpler way?
Thanks.
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.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: 3 questions: to_location; chaining events ; store_unit
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.
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.
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.
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]
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]
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: 3 questions: to_location; chaining events ; store_unit
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
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: 3 questions: to_location; chaining events ; store_unit
Thank you. I thought it would be a good idea to link
event
s 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]
I had a suspicion there was a better way. Thanks.WhiteWolf wrote: ↑December 29th, 2020, 4:30 pmCode: Select all
[if] [have_unit] id=MyLeader status=poisoned [/have_unit] [then]
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.)beetlenaut wrote: ↑December 29th, 2020, 5:00 pmYou 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.
Anyhow, thanks, beetlenaut. I didn't realize that the flag in the Map Editor had an ADD function. Problem solved.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: 3 questions: to_location; chaining events ; store_unit
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.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
Re: 3 questions: to_location; chaining events ; store_unit
why would you use the +tag and not put it in the same event?
Re: 3 questions: to_location; chaining events ; store_unit
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]
name=turn 2,moveto
? Do all the names have to match? Or can just one match?Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: 3 questions: to_location; chaining events ; store_unit
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
Is equivalent to
Therefore this question:
Cutting out the action wml part for visibility, your posted code is currently equivalent to this:
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
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:
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
stuff
[/tag]
[+tag]
other stuff
[/tag]
Code: Select all
stuff
other stuff
[/tag]
doesn't make much sense. What is there to match? You're just expanding the end of the event with more stuff.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?
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]
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
Code: Select all
[unit_type]
[abilities]
{ABILITY_1}
{ABILITY_2}
{ABILITY_3}
...
[/abilities]
[/unit_type]
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
Re: 3 questions: to_location; chaining events ; store_unit
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
Re: 3 questions: to_location; chaining events ; store_unit
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.
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.
Re: 3 questions: to_location; chaining events ; store_unit
Oh my goodness. I totally did not understand the
I thought...
Well, never mind what I thought. Thanks for explaining what the tag is for and not for.
I rewrote my events. The
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.
+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. 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.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: 3 questions: to_location; chaining events ; store_unit
No worries, trial and error is probably the best way to learn
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
You may not realize that now, but this is actually a very good approach.I wonder how much of my code is not exactly logical and proper? It all seems to work, though.
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
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
Re: 3 questions: to_location; chaining events ; store_unit
Thanks for the words of encouragement.WhiteWolf wrote: ↑December 31st, 2020, 11:41 am No worries, trial and error is probably the best way to learn
You may not realize that now, but this is actually a very good approach.I wonder how much of my code is not exactly logical and proper? It all seems to work, though.
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
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]
Code: Select all
[have_unit]
id=Moho
$this_unit.level
less_than=2
[/have_unit]
[or]
be used with have_unit
to test for level=0 or level=1?Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: 3 questions: to_location; chaining events ; store_unit
[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
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: 3 questions: to_location; chaining events ; store_unit
As beetlenaut says, so the standard unit filter keys are recognized. There is a
Otherwise you could just use a formula for this.
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]
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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