Ephraim's WML questions

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.
User avatar
Ravana
Forum Moderator
Posts: 2953
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Ephraim's WML questions

Post by Ravana »

Provided you have unit in $unit {VARIABLE unit.variables.hp.upgrades 1} and unstore_unit then.

https://github.com/ProditorMagnus/Agele ... s.cfg#L197

For the record, the code you posted is not suitable for "To keep your code readable so that others can easily help you, make sure to indent it".
User avatar
Ephraim
Posts: 47
Joined: July 3rd, 2017, 2:03 pm
Location: The Great Library of WML, Studiying it

Re: Ephraim's WML questions

Post by Ephraim »

So:

Code: Select all

[option] 
    label= +8hp
    [command]
        [modify_unit]
            [filter] 
                x=$x1
                y=$y1
            [/filter] 
            max_hitpoints=+8
        [/modify_unit] 
        [set_variable] 
            name=unit.variables.hp.upgrades
            literal=+1
        [/set_variable] 
        [unstore_unit] 
            variable=unit.variables.hp.upgrades
            find_vacant=no
        [/unstore_unit] 
    [/command] 
[/option]
Then, it should work correctly, or will happen that every time the unit buys an upgrade, the variable will reset to 1 again, since in the code says: literal=+1?
The Great Library of WML is huge and extense. I must find the book who will lead me to create a perfect campaign.
Future Project: History of Vindalf
User avatar
Ravana
Forum Moderator
Posts: 2953
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Ephraim's WML questions

Post by Ravana »

I have not used literal enough to say what it should do, see documentation for that. But + is most likely string addition there. To actually change variables there is VARIABLE_OP.
User avatar
Ephraim
Posts: 47
Joined: July 3rd, 2017, 2:03 pm
Location: The Great Library of WML, Studiying it

Re: Ephraim's WML questions

Post by Ephraim »

Ravana wrote:I have not used literal enough to say what it should do, see documentation for that. But + is most likely string addition there. To actually change variables there is VARIABLE_OP.
But, for changing a variable with {VARIABLE_OP}, is necessary that the variable exists? Or if the variable doesn't exist, the VARIABLE_OP just creates one with value=+1 (if the addition in that case is +1, obviously)?
The Great Library of WML is huge and extense. I must find the book who will lead me to create a perfect campaign.
Future Project: History of Vindalf
User avatar
Ravana
Forum Moderator
Posts: 2953
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Ephraim's WML questions

Post by Ravana »

Most likely unspecified behavior, but I expect it starts with 0 when missing. Still it makes sense to initialise that variable yourself.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Ephraim's WML questions

Post by enclave »

Hi, I would also not recommend using unit.variables.hp.upgrades it would be not lua-friendly (at least to the best of my abilities..), when I tried to code something with array inside variables in LUA, i couldn't.. so I had to change my path into something like unit.variables.hp_upgrades
It's not important, but I'm just sharing my negative experience :)

I think u need to use [unstore_unit] variable=unit
and not the full path, but maybe it works with full path too, idk :)

I wish I could help more, but same as Ravana I haven't used literals enough to commend anything. Same with labels in options or with +numbers, not sure if it will add 8 hp and not just try to concatenate string "8".
I think there was something special like "increase_maximum_hitpoints" or something similar.. to say for sure need to look documentation on [modify_unit].

Good luck :)
Post Reply