[closed] Need Help for $side_number, or maybe variable

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
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

[closed] Need Help for $side_number, or maybe variable

Post by Soshen_ »

I have an issue with this code, i know my mistake. So I explain what goes wrong, I want to save the name of the cloak in a variable with the name "sideX_cape" where X is the $side_number. I custom a MOBA-like add-ons, so each side control only 1 leader and can't recruit. If you have an alternative it would be great. If we can buy an item multiple times (or take different items of the same type) it's not good for me.

I've tried with side1_cape instead and it's work, but just for the first player /:

And just for precision, I've start WML just 48h ago and a thing like 16h on code, so maybe I do a newbie mistake xD (surely)

Thanks for you're help and sorry for my english if I've do mistakes ^^"

Code: Select all

message="Cape des Veilleurs - 100 Or
Vous rend invisible la nuit, cependant elle semble ralentit tout ce qu'elle touche
+15 Damage, Slowed at Night (not healed), Nightwalker abilty"    # Nom de l'item + Prix
[command]
    [if]
        [variable]
            name=buyergold
            greater_than_equal_to=60   # Vérification des golds de l'acheteur
        [/variable]
        [then]
            [if]
                [not]
                [variable]
                    name="side" + $side_number + "_cape"
                    equals=0
                [/variable]
                [/not]
                [then]
                    [message]
                        speaker=narrator
                        caption=Shopkeeper
                        side_for=$side_number
                        message="Désolé, vous ne pouvez pas posséder deux capes à la fois."
                        image=portraits/goblins/rouser.png
                    [/message]
                [/then]
                [else]        
                    [gold] 
                        side=$side_number
                        amount=-105             # Débit
                    [/gold]
                    [set_variable]
                        name="side" + $side_number + "_cape"
                        value="Cape des Veilleurs"  # Stockage du nom de l'objet acheté dans la variable correspondante
                    [/set_variable]
                    [object]
                        duration=forever        # Durée
                        silent=yes
                        [filter]
                            side=$side_number
                            x,y=$target.x,$target.y
                        [/filter]
                        [effect]
                            apply_to=attack
                            increase_damage=15
                        [/effect]
                        [effect]
                            apply_to=abilty
                            new_ability=nightwalker
                        [/effect]
                    [/object]
                [/else]
            [/if]
        [/then]
        [else]
            [message]
                speaker=narrator
                caption=Shopkeeper
                side_for=$side_number
                message="Désolé, mais vous n'avez pas assez d'or."
                image=portraits/goblins/rouser.png
            [/message]
        [/else]
    [/if]
[/command]
Last edited by Soshen_ on April 2nd, 2024, 4:29 am, edited 1 time in total.
User avatar
Ravana
Forum Moderator
Posts: 3021
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Need Help for $side_number, or maybe variable

Post by Ravana »

name="side$side_number|_cape"

| acts as explicit end of variable name.
white_haired_uncle
Posts: 1230
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Need Help for $side_number, or maybe variable

Post by white_haired_uncle »

It sounds to me like you're ready to learn about arrays. I can't find a good intro link, maybe someone else will know where to start. I think you'll want to start with something like this:

Code: Select all

{VARIABLE cape[$side] _"Cape des Veilleurs"}  # the cape for side $side
and then work your way up to

Code: Select all

{VARIABLE cape[$side][$number] _"Cape des Veilleurs"}  # each side can have multiple capes, this is cape number $number for side $side
and eventually something like

Code: Select all

{VARIABLE items[$side].capes[$number].name _"Cape des Veilleurs"} # This will make sense later
I'm probably wrong about where you'll end up, but work on the first example to start.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3021
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Need Help for $side_number, or maybe variable

Post by Ravana »

First examples are wrong, you cant store data in tag without key, so should be
{VARIABLE cape[$side].x_"Cape des Veilleurs"} # the cape for side $side
{VARIABLE cape[$side].x[$number].y _"Cape des Veilleurs"} # each side can have multiple capes, this is cape number $number for side $side
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

Ravana wrote: March 30th, 2024, 3:15 pm name="side$side_number|_cape"

| acts as explicit end of variable name.
OMG Thanks a lot !!
Where can I find this answer in the wiki.doc ? I've search, but not found this anywhere.
I think I can learn some other things at the same place 😂
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

white_haired_uncle wrote: March 30th, 2024, 3:24 pm It sounds to me like you're ready to learn about arrays. I can't find a good intro link, maybe someone else will know where to start. I think you'll want to start with something like this:

Code: Select all

{VARIABLE cape[$side] _"Cape des Veilleurs"}  # the cape for side $side
and then work your way up to

Code: Select all

{VARIABLE cape[$side][$number] _"Cape des Veilleurs"}  # each side can have multiple capes, this is cape number $number for side $side
and eventually something like

Code: Select all

{VARIABLE items[$side].capes[$number].name _"Cape des Veilleurs"} # This will make sense later
I'm probably wrong about where you'll end up, but work on the first example to start.
I've already use array in javascript and php but array in WML look a lot different to me, so I've try to avoid it in my code.

But it's obviously more optimized for sure, less code and less répétitions. I need to practice, do you know a simple mod using a lot of array ? I learn better when I just decypher what things do and then try to custom for test.
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

When you say than array need a key it's like array in wml are by default a multiple array ?
Last edited by Soshen_ on March 30th, 2024, 6:48 pm, edited 1 time in total.
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

Do you know if there's a french community in WML ?
User avatar
Ravana
Forum Moderator
Posts: 3021
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Need Help for $side_number, or maybe variable

Post by Ravana »

https://wiki.wesnoth.org/VariablesWML#V ... bstitution

WML array is WML, so array with 2 elements can look like
[a]
b=c
[/a]
[a]
b=d
[/a]

WML does not let you create
[a]
c
[/a]
[a]
d
[/a]

Therefore it is $a[1].b to get d, not $a[1].
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

Ok so i can make i thing like this for store players items ?

[equipped.stuffs] # Leader Side 1
helmet=iron
torso=iron
legs=iron
boots=iron
cape=iron
hand=leather
[equipped.stuffs/] # Leader Side 2
helmet=""
torso=""
legs=""
boots=iron
cape=coat
hand=leather
[equipped.stuffs/] .... to Leader 6

And call gear value with $equipped.stuffs[1].helmet to get (or set) the value ?

Because if it's correct. I Think I'm on the way to not sleep toonight and refactor my Add-Ons xD
User avatar
Ravana
Forum Moderator
Posts: 3021
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Need Help for $side_number, or maybe variable

Post by Ravana »

Without .stuffs

In general idea looks good, check [set_variables] for easier way how to create arrays of wml objects.

https://wiki.wesnoth.org/InternalAction ... ays_of_WML
Soshen_
Posts: 13
Joined: May 12th, 2020, 12:01 pm

Re: Need Help for $side_number, or maybe variable

Post by Soshen_ »

Thanks for you're help and you're quick and precise answers ! ^^


You rock !
~ a guitar hero player :lol: :lol:
Post Reply