[closed] Need Help for $side_number, or maybe variable
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.
[closed] Need Help for $side_number, or maybe variable
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 ^^"
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.
Re: Need Help for $side_number, or maybe variable
name="side$side_number|_cape"
| acts as explicit end of variable name.
| acts as explicit end of variable name.
-
- 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
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:
and then work your way up to
and eventually something like
I'm probably wrong about where you'll end up, but work on the first example to start.
Code: Select all
{VARIABLE cape[$side] _"Cape des Veilleurs"} # the cape for side $side
Code: Select all
{VARIABLE cape[$side][$number] _"Cape des Veilleurs"} # each side can have multiple capes, this is cape number $number for side $side
Code: Select all
{VARIABLE items[$side].capes[$number].name _"Cape des Veilleurs"} # This will make sense later
Speak softly, and carry Doombringer.
Re: Need Help for $side_number, or maybe variable
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
{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
Re: Need Help for $side_number, or maybe variable
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.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:
and then work your way up toCode: Select all
{VARIABLE cape[$side] _"Cape des Veilleurs"} # the cape for side $side
and eventually something likeCode: Select all
{VARIABLE cape[$side][$number] _"Cape des Veilleurs"} # each side can have multiple capes, this is cape number $number for side $side
I'm probably wrong about where you'll end up, but work on the first example to start.Code: Select all
{VARIABLE items[$side].capes[$number].name _"Cape des Veilleurs"} # This will make sense later
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.
Re: Need Help for $side_number, or maybe variable
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.
Re: Need Help for $side_number, or maybe variable
Do you know if there's a french community in WML ?
Re: Need Help for $side_number, or maybe variable
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].
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].
Re: Need Help for $side_number, or maybe variable
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
[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
Re: Need Help for $side_number, or maybe variable
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
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
Re: Need Help for $side_number, or maybe variable
Thanks for you're help and you're quick and precise answers ! ^^
You rock !
~ a guitar hero player
You rock !
~ a guitar hero player