enclave's WML Macros questions Thread

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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

enclave's WML Macros questions Thread

Post by enclave »

Hello, I will try to put all my questions regarding WML and macros here.. I hope its better this way..

1) What is the easiest and proper way to create something like this {DO_ACTION_NUMBER_$number} ?
If we assign some number to the $number {VARIABLE $number 1} then
I know that $number doest work, but {DO_ACTION_NUMBER_{NUMBER}} would turn into {DO_ACTION_NUMBER_"1"}
which is not bad.. but i find it messy and I can not be 100% sure it's not going to create any bugs.. and I would require to insert my code into another {} to receive {NUMBER}.. so it is a solution I don't like. Is there a better one?
Somebody told to use #ifdef but after reading help on it I didn't find anything that would help me with my problem, maybe I simply somehow don't understand it..
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

The reason I want to do {DO_NUMBER_$num} is because I want to create list of custom abilities in array..
And then insert them into [unit] just by specifying their array number..
for example

Code: Select all

{CREATE_UNIT $type $name $side $x $y ... $ability_number}
which is something like:

Code: Select all

#define CREATE_UNIT TYPE NAME SIDE X Y ... ABILITY_NUMBER
[unit]
type={TYPE}
name={NAME}
side={SIDE}
x={X}
y={Y}
...
[modifications]
[object]
...
[effect]
...
[abilities]
{INSERT_ABILITY_{ABILITY_NUMBER}}
[/abilities]
....
#enddef
The other problem i'm coming across is that tags inside the [unit] not working.. which limits me to use any
[if][then].. so I will have problems with units who have more than 1 ability.. but maybe I will solve it with lua, i dont know yet..
for now i only want to know if there is way to use {DO_$something} macros..
Thanks everyone... in advance!
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: enclave's WML Macros questions Thread

Post by ChaosRider »

I would do it in diffrent way.
1. I would add to unit one specific ability (without name but with id, players wont see it but it will be there)
2. By this (inside your ability definition):
Spoiler:
you can put there event.
3. Inside your event you choose name=recruit,recal,start
4. You have to filter units with this your special ability
Spoiler:
5. they should be stored already by "unit", now you have to choose random some new ability, add it and delete your special one.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thanks ChaosRider, there are some problems implementing your version into my code and also some questions about it :)
The problem is I don't use standard recruit, but a right-click message dialogue.. so event recruit etc won't work.. of coz maybe i could use fire event somewhere also, so I'm sure I could work around to find way to use your version.. thanks.

The questions are:
1) what means [+abilities]?
2) why you starting code with closing tag [/abilities]? was it mistype or its the way it should work? i'm not very good in some specific parts of wml.. some of them like [+abilities] i simply don't know at all.. please explain if you have time.

3) So basically your idea is that I recruit unit, then modify it with array and then unstore?
3.1) What is the plan inside the event=recruit? [filter]...[/filter] but then which way you modify the ability id?
Thank you!

One of my ideas how to make it work was to work with array directly.. then unstore. and maybe its the best option if only i don't find nice way to use {FUNCTION_$number}

PS. hmm I guess your idea is quite good.. Modifying unit after i recruit it.. I guess I could just [store] and then add as many abilitiy IDs into unit array as I like.. and [unstore]..
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

@enclave: What you want is emulate a "function", wich is something WML does not feature. The way to emulate a function is using [event] after store arguments in variables. Take into acount that [fire_event] takes almost no computer memory, however every time you use a macro, it takes full macro length memory space from user. If I would you, I would use something similar to this structure (I took it from my add on without modify it, because I think has same example power)

Code: Select all

#define WORLD_CONQUEST_TEK_TRAIN RECRUITER_VAR
[set_variables]
    name=training
    to_variable={RECRUITER_VAR}.training
[/set_variables]
[fire_event]
    name=wct_training_effects
[/fire_event]
#enddef
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thanks Tekelili, for fire_event advice.. optimizing my mod is also on my todo list in some future, so your advice will come handy ;)

Speaking about it, how much actually difference fire_event vs macros can make?
My mod has quite balanced macros amounts.. spread into different parts of it.. I don't think that if a person does 1 recruit in his turn, using macro would feel any significant difference than if it was fire_event based.. or am I wrong?
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

There are 2 common reasons for not convert a macro into event:
a) Macro is used where [event] is not supported, like inside [side] or [ability]
b) Macro has modular propose rather than function one. This mean that probably macro is used only once along code, or if is used several times is still just for make code redeable and pretty short (like FOREACH macro)

In any other case, use to be better convert macros to event.

Btw, if you are trying to give abilities from an array, you should consider use [insert_tag], wich mostly will solve your problem with "how the hell write a different macro based on a variable value"
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thank you very much Tekelili, I think I will start using fire events now, where possible.. maybe it will make code at least a bit quicker :)

i considered insert tag and even tried to use it, but mostly came to solution that i need something better..

if nobody say that there is way to use {MACRO_$macro2} or if more people say that there is absolutely no way to do it.. I think my best option will be to try to work with store/unstore.. modifying the unit array already after unit was created.. or to store unit into array first and then unstore modified version.. will try to involve fire_event.. to see how it works :)
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

enclave wrote:Thank you very much Tekelili, I think I will start using fire events now, where possible.. maybe it will make code at least a bit quicker :)
You mostly will not gain speed perfomance. You will be only saving RAM consumed and savefile size, and in rare case RAM consumed was so big that slowed perfomance, then you would be gaining speed.

It took me quite time understand what a macro does from resources point of view... and it is mostly nothing. A macro only saves hard disk memory, but no RAM memory. Hard disk size consumed use to be pretty irrelevant compared with RAM consumed. However, what macros do pretty well is improve code readibility, and should be used from that point of view.

As convert a macro into a event is pretty straight forward, I often do it only after realize is a good idea, but dont care too much to consider it in first instance while coding.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thank you Tekelili,
by the way I was thinking about [event] inside of [unit] and I realized I don't understand what benefit this could give me..

if I put inside of [unit] [event] id=blabla name=custom_event_1 [chat] message="hello world!" [/chat][/event][/unit]

so I could then use [fire_event] name=custom_event_1 [/fire_event] ?
What could be the use of it? what could be useful instead of [chat] message? i put chat message just as useless example..

what do people usually use [event] inside of [unit] for?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thanks Ravana, will read it;)
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

enclave wrote:what do people usually use [event] inside of [unit] for?
Most clear example is mainline feeding ability. Only way to increase necrophage max hitpoints upon killing a unit is via event. Only way that event is writing in every scenario with a necrophage is write event inside unit.

It is also usefull to write events related to units in next scenarios of campaigns without have to write code in every [scenario] tag.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thanks Tekelili, so it is mostly for compaigns and not for multiplayer scenarios then?
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

enclave wrote:Thanks Tekelili, so it is mostly for compaigns and not for multiplayer scenarios then?
In general... yes; but not exactly. Its usefullness is defined as event is written every time unit is on scenario and event is removed when unit dies (if no other unit with same event still alive). So in a single multiplayer scenario, theorically could have some use like "when player do X give him a teasure but only if his first recruit is still alive". Sure you can do it from a scenario [event], but could be more clean write event inside player 1st recuit "[unit]".
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Post Reply