Complicated WML. Please help!

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
Clonkinator
Posts: 676
Joined: July 20th, 2006, 4:45 pm
Location: Germany

Complicated WML. Please help!

Post by Clonkinator »

Hi there,
maybe you know my mod "SurvivalXtreme". If you do, you surely also know that a player that just killed an enemy gains back 3 MP. So far, so good. However, recently I tried to change it in a way so it restores half of your max. MP instead. This works fine using this code if the max. moves of that unit haven't been modified:

Code: Select all

{VARIABLE killer_movement_bonus $killer.movement}
{VARIABLE_OP killer_movement_bonus multiply 0.5}
{VARIABLE killer.moves $killer_movement_bonus}
{VARIABLE killer.attacks_left 1}
However, if the killer raised his movement in one of the shops, it still just restores half of the original amount of MP. This is not the way I want it to be though... Is there any way to make this function restore half of the real max. movement of a unit? I already tried to count the number of times the movement is increased, set killer.moves to killer.movement, then add the count of the increases and then half killer.moves. However, it still didn't do anything else than the code listed above. Can anybody tell me how to make this work?

Other than that, the [show_if]-tag in the [options]-tag seems not to work. (I'm using Wesnoth Version 1.2.4)
Derekkk
Posts: 64
Joined: April 25th, 2007, 5:43 pm

Post by Derekkk »

I think you might be using [object] tags to raise the mp of the units. Instead, you can try to use store_unit and then change the variable corresponding to maximum mp. Unstore the unit afterwards, of course.

Also, the [show_if] tag only works in 1.3.x, I think.

Derekkk
meriton
Posts: 77
Joined: March 17th, 2007, 1:17 pm

Post by meriton »

Short version: You can not use $ to insert the value of a variable in the the value argument of the {VARIABLE} macro. If you need that, use {VARIABLE_OP} with operation "format" instead.

Long version:The {VARIABLE} macro uses [set_variable] and specifies the new value using the "value" attribute. [set_variable]value= is the only WML attribute that does not perform variable substitution (in the 1.2 branch, that is). Hence, after the third line of the snippet you posted, the variable "killer.moves" stores the value "$killer_movement_bonus" and not the value of "killer_movement_bonus".

---

==> Use {VARIABLE_OP killer.moves format $killer_movement_bonus} instead. Does it work now?

BTW, killer.moves is a perfectly ordinary variable. There is no need to perform computation in a separate variable, you could just as well write

Code: Select all

{VARIABLE_OP killer.moves format $killer.movement}
{VARIABLE_OP killer.moves multiply 0.5}
{VARIABLE killer.attacks_left 1}
User avatar
governor
Posts: 267
Joined: December 8th, 2006, 12:32 am

Post by governor »

meriton wrote:Short version: You can not use $ to insert the value of a variable in the the value argument of the {VARIABLE} macro. If you need that, use {VARIABLE_OP} with operation "format" instead.

Long version:The {VARIABLE} macro uses [set_variable] and specifies the new value using the "value" attribute. [set_variable]value= is the only WML attribute that does not perform variable substitution (in the 1.2 branch, that is). Hence, after the third line of the snippet you posted, the variable "killer.moves" stores the value "$killer_movement_bonus" and not the value of "killer_movement_bonus".

---

==> Use {VARIABLE_OP killer.moves format $killer_movement_bonus} instead. Does it work now?

BTW, killer.moves is a perfectly ordinary variable. There is no need to perform computation in a separate variable, you could just as well write

Code: Select all

{VARIABLE_OP killer.moves format $killer.movement}
{VARIABLE_OP killer.moves multiply 0.5}
{VARIABLE killer.attacks_left 1}
I am fairly certain you are 100% mistaken.

{VARIABLE var1 $var2.xxxx} is valid.
Last edited by governor on July 16th, 2007, 3:34 am, edited 1 time in total.
User avatar
governor
Posts: 267
Joined: December 8th, 2006, 12:32 am

Post by governor »

You have three unit.variables to consider to achieve your effect.

max_moves
moves
movement

I can't really be certain, but I think you need to set moves to 50% of max_moves.

Good Luck
meriton
Posts: 77
Joined: March 17th, 2007, 1:17 pm

Post by meriton »

Governor:
I just tested it and couldn't believe my eyes, it looks like you're right. The only real explanation of the various substitution kinds I found was Cyberjack's guide to variable expansion, where he writes:
  • No substitution is performed in these keys:
    • [set_variable]value=
I have updated VariablesWML with a request for clarification on this matter.
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

  • No substitution is performed in these keys:
    • [set_variable]value=
Variable substitution was added to the value key in version 1.3.2 (see the changelog), but yes, it should also be added to the wiki (documentation happens after the fact...).
User avatar
governor
Posts: 267
Joined: December 8th, 2006, 12:32 am

Post by governor »

Substitution in set_variable::value has worked in 1.2 and perhaps even 1.1. It doesn't work as the non name key in the [variable] tag in these versions.
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

governor wrote:Substitution in set_variable::value has worked in 1.2 and perhaps even 1.1.
Not the full substitution with multiple dollar signs (indexing array values...), which is a relatively new feature AFAIK.
User avatar
governor
Posts: 267
Joined: December 8th, 2006, 12:32 am

Post by governor »

Rhuvaen wrote:
governor wrote:Substitution in set_variable::value has worked in 1.2 and perhaps even 1.1.
Not the full substitution with multiple dollar signs (indexing array values...), which is a relatively new feature AFAIK.
I was only referring to the simple substitution of format x1.x2 that meriton had discussed in his first post.
Clonkinator
Posts: 676
Joined: July 20th, 2006, 4:45 pm
Location: Germany

Post by Clonkinator »

governor wrote:You have three unit.variables to consider to achieve your effect.

max_moves
moves
movement

I can't really be certain, but I think you need to set moves to 50% of max_moves.

Good Luck
I already tried max_moves. For some weird reason, the result I get from this always is 2 MP, no matter which unit I am using and no matter how many movement it has.
Derekkk wrote:I think you might be using [object] tags to raise the mp of the units. Instead, you can try to use store_unit and then change the variable corresponding to maximum mp. Unstore the unit afterwards, of course.
Indeed, I'm using [object] for this. I'll try this method, thanks.
Derekkk wrote:Also, the [show_if] tag only works in 1.3.x, I think.
Really? Dang. Why are all the useful features for 1.3.3+ only. :x
I'll leave it in, however. Might come in handy if I port it to some 1.3.x or some 1.4.x version.
User avatar
Dovolente
Posts: 140
Joined: April 17th, 2007, 9:02 pm
Location: USA, Mountain West
Contact:

Post by Dovolente »

If [showif] indeed works only in 1.3, it needs to be stated on the wiki--it isn't (and I just spent an hour figuring that out the hard way, then came to search for [showif] on the forum and found this).

The wiki is usually very good at keeping that straight (nice job, whoever updates it!). Looks like this one fell through the cracks.
Post Reply