Where to place my event?

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
Katz
Posts: 6
Joined: June 4th, 2010, 6:28 pm

Where to place my event?

Post by Katz »

Hello again everyone!

I'm still working on my custom thief units. I developed a "pickpocket" ability. It is different from the one on the wiki, because I found that one didn't work, and I think it had a whole lot of extra code. Anyways, the general code is located in my campaign folder, in a utils/abilities.cfg file. It follows the general idea below:

Code: Select all

#define WEAPON_SPECIAL_PICKPOCKET
[dummy]
   #ability name and description
[/dummy]
[/specials]
[/attacks]

[event]
   #the event that triggers adding one gold to the side of the attacker for each successful attack made with this special
   #filter is made with the id of the dummy special
[/event]

[+specials]
[+events]
#enddef
It works great, only if I give this special attack to several units, and the event is repeated for each different unit type with this special attack. By that, I mean if I only have a Street Urchin in game, he steals one gold alright.
But if I add a Pickpocket unit, then they both steal two golds each time, which would be expected since both units contain that event. In effect, the event is present twice, and will therefore trigger twice.

So my question is: Where can I place that event so that it will still work, but only appear once in the code?
I tried putting it in my abilities.cfg file, outside any define tags, but then it doesn't work. Should I place it in my main campaign file? Or could I place it in another file, then make sure that file is loaded when the campaign launches? How to do that?

Thanks !
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Where to place my event?

Post by zookeeper »

So if two different unit types have the same event-driven ability and you then have units of both types in a scenario, the event gets duplicated? I haven't tested it myself, but that sounds very plausible to me. I'll try it out a bit later and file a bug report if that's really the case unless someone beats me to it.

EDIT: Well, I'm not sure why I thought I needed to test that. Yes, that's the way it works: unit type events are handled based on unit type. If you want to use the same event in several unit types, you either need to:

1) add some filtering so that the event which unit type X gets will only work for units of type X, and the event which unit type Y gets will only work for units of type Y (that is, not for any units with the dummy ability), and so on.

2) write the event so that its effects don't get duplicated no matter how many times it's duplicated in a row. Doesn't sound feasible in your case, however.
Katz
Posts: 6
Joined: June 4th, 2010, 6:28 pm

Re: Where to place my event?

Post by Katz »

I'm not 100% sure that's what happened, but after much testing, I came to that conclusion.
I assume the code is added once you add the unit. Since the even is not in the ability tag, it applies once each time it's added.

I'll try to look if it is possible to make it not be cumulative, seeing as how you can do that for healing abilities, for example.

However, another fix would be to add the event in only one point of the code. I'll try adding it to the scenario to see if that would work.
However, it would be simpler if I could just include a file, containing those abilities events, into each of my scenarios. Is there a way to include a file into another?

----------------
edit: Adding the event in the scenario does work fine. If anyone can tell me how to include a file into a scenario (if it is even possible), it would be awesome ! :D
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Where to place my event?

Post by Max »

e.g. {~add-ons/MyCampaign/special/eventstuff.cfg} should work.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Where to place my event?

Post by Anonymissimus »

Katz wrote:If anyone can tell me how to include a file into a scenario (if it is even possible), it would be awesome ! :D
Half of any wml code consists of stuff included into each other...just don't think of macros as "functions", their code gets inserted instead.
E.g. map_data="{~some_path/some.map}" only includes some.map's content at that position between the "". Some (usually old) campaigns actually have their map data included in the scenario cfg, it's equivalent.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Katz
Posts: 6
Joined: June 4th, 2010, 6:28 pm

Re: Where to place my event?

Post by Katz »

That's what I thought. I'll try it then ! Thank you ! :)
Post Reply