Complicated WML. Please help!
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.
-
- Posts: 676
- Joined: July 20th, 2006, 4:45 pm
- Location: Germany
Complicated WML. Please help!
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:
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)
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}
Other than that, the [show_if]-tag in the [options]-tag seems not to work. (I'm using Wesnoth Version 1.2.4)
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
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.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 writeCode: Select all
{VARIABLE_OP killer.moves format $killer.movement} {VARIABLE_OP killer.moves multiply 0.5} {VARIABLE killer.attacks_left 1}
{VARIABLE var1 $var2.xxxx} is valid.
Last edited by governor on July 16th, 2007, 3:34 am, edited 1 time in total.
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:
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:
I have updated VariablesWML with a request for clarification on this matter.
- 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...).
- No substitution is performed in these keys:
- [set_variable]value=
Try some Multiplayer Scenarios / Campaigns
Not the full substitution with multiple dollar signs (indexing array values...), which is a relatively new feature AFAIK.governor wrote:Substitution in set_variable::value has worked in 1.2 and perhaps even 1.1.
Try some Multiplayer Scenarios / Campaigns
I was only referring to the simple substitution of format x1.x2 that meriton had discussed in his first post.Rhuvaen wrote:Not the full substitution with multiple dollar signs (indexing array values...), which is a relatively new feature AFAIK.governor wrote:Substitution in set_variable::value has worked in 1.2 and perhaps even 1.1.
-
- Posts: 676
- Joined: July 20th, 2006, 4:45 pm
- Location: Germany
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.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
Indeed, I'm using [object] for this. I'll try this method, thanks.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.
Really? Dang. Why are all the useful features for 1.3.3+ only.Derekkk wrote:Also, the [show_if] tag only works in 1.3.x, I think.
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.
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.
The wiki is usually very good at keeping that straight (nice job, whoever updates it!). Looks like this one fell through the cracks.