How do you get a number and use it from sides having the same team name
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.
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
How do you get a number and use it from sides having the same team name
Hi I am attempting to store sides in order to count how many players there are on one team in order to give a bonus to the other player. I am not sure how to use the foreach syntax to do this properly. I have been looking over the conditional actions (https://wiki.wesnoth.org/ConditionalActionsWML) for a while today but it is blowing over my head I guess. Would the following code perhaps work?
Code: Select all
[store_side]
team_name=Refugees
variable=player_count
[/store_side]
[foreach]
array=player_count.team_name
variable=la_devilry_bonus
[do]
{VARIABLE_OP la_devilry multiply $la_devilry_bonus}
{VARIABLE_OP la_devilry multiply $la_devilry_bonus}
[/do]
{CLEAR_VARIABLE player_count}
[/foreach]
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: How do you get a number and use it from sides having the same team name
This would be more correct as far as [foreach] goes, though I'm not sure if it's exactly what you want:
Code: Select all
[store_side]
team_name=Refugees
variable=players
[/store_side]
[foreach]
array=players
variable=player
[do]
{VARIABLE_OP la_devilry multiply $la_devilry_bonus}
[/do]
[/foreach]
{CLEAR_VARIABLE players}
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: How do you get a number and use it from sides having the same team name
This will store ONLY sides with team name "Refugees"...LordAwsomeness wrote: ↑May 9th, 2018, 11:42 pmCode: Select all
[store_side] team_name=Refugees variable=player_count [/store_side]
The count of Refugees would be this variable after your code above: $player_count.length
You could store all sides with this code
Code: Select all
[store_side]
variable=player_count
[/store_side]
Code: Select all
{FOREACH player_count i}
[if]
[variable]
name=player_count[$i].team_name
equals="Refugees"
[/variable]
[then]
{VARIABLE_OP la_devilry multiply $la_devilty_bonus}
[/then]
[else]
[/else]
[/if]
##
[if]
[variable]
name=player_count[$i].team_name
equals="Goblins"
[/variable]
[then]
{VARIABLE_OP la_devilry multiply $la_devilty_bonus_for_goblins}
[/then]
[else]
[/else]
[/if]
{NEXT i}
Code: Select all
[modify_side]
side=2
gold=$la_devilry
[/modify_side]
Code: Select all
{FOREACH player_count i}
[if]
[variable]
name=player_count[$i].team_name
equals="Refugees"
[/variable]
[then]
{VARIABLE la_devilry $player_count[$i].gold}
{VARIABLE_OP la_devilry multiply $la_devilty_bonus}
[modify_side]
side=$player_count[$i].side
gold=$la_devilry
[/modify_side]
[/then]
[else]
[/else]
[/if]
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
I actually only want to store sides with the team_name refugees. I need to get a number from it and use a {VARIABLE_OP la_devilry multiply $teamnumber} so that the devilry variable bonus is increased by the number of players with the team_name=Refugees.
and I'm pretty sure the {FOREACH} macro is about to become deprecated in 1.15 so i am trying to avoid using it lol.enclave wrote: ↑May 10th, 2018, 12:06 amCode: Select all
[store_side] team_name=Refugees variable=player_count [/store_side]
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
How would I use the array to get the number of side/players with the team_name=refugees?Pentarctagon wrote: ↑May 9th, 2018, 11:58 pm This would be more correct as far as [foreach] goes, though I'm not sure if it's exactly what you want:Code: Select all
[store_side] team_name=Refugees variable=players [/store_side] [foreach] array=players variable=player [do] {VARIABLE_OP la_devilry multiply $la_devilry_bonus} [/do] [/foreach] {CLEAR_VARIABLE players}
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Re: How do you get a number and use it from sides having the same team name
Then you probably only need to do:LordAwsomeness wrote: ↑May 10th, 2018, 12:36 am I actually only want to store sides with the team_name refugees. I need to get a number from it and use a {VARIABLE_OP la_devilry multiply $teamnumber} so that the devilry variable bonus is increased by the number of players with the team_name=Refugees.
and I'm pretty sure the {FOREACH} macro is about to become deprecated in 1.15 so i am trying to avoid using it lol.
Code: Select all
[store_side]
team_name=Refugees
variable=player_count
[/store_side]
{VARIABLE_OP la_devilry multiply $player_count.length}
1) There will be some 3 years until 1.15 (am I wrong?), you probably worrying in vain..
2) You can create this macro yourself... even if they remove it, you can recreate it easily, maybe with different name, it depends.
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
why does the string come back as empty? the team name is correct. the current scenario i am using it on has 4 teams with that name. I could easily just write in multiply by 4 but i want this to work on other scenarios without having to recreate the unique codes every single time or without having to drop it in the scenario prestart event if i can. Id rather have one code that works by using a string or array or whatever this is lol.enclave wrote: ↑May 10th, 2018, 12:42 am Then you probably only need to do:Keep in mind it may be 0, then la_devilry may be 0 too... whatever it is..Code: Select all
[store_side] team_name=Refugees variable=player_count [/store_side] {VARIABLE_OP la_devilry multiply $player_count.length}
1) There will be some 3 years until 1.15 (am I wrong?), you probably worrying in vain..
2) You can create this macro yourself... even if they remove it, you can recreate it easily, maybe with different name, it depends.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Re: How do you get a number and use it from sides having the same team name
It may be "user_team_name" (the one that shows for you... the real name may be different)
try to do:
1)
2) use command
:debug
and then command
:inspect
(inspect will make a menu popup... where you can check all variables.. including team names and your stored arrays..)
I'm not sure if filter works for user_team_name... I hope it does..
try to do:
1)
Code: Select all
[store_side]
user_team_name=Refugees
variable=player_count
[/store_side]
{VARIABLE_OP la_devilry multiply $player_count.length}
:debug
and then command
:inspect
(inspect will make a menu popup... where you can check all variables.. including team names and your stored arrays..)
I'm not sure if filter works for user_team_name... I hope it does..
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
no I'm editing the scenario by hand, i set the team_name myself. is it perhaps the quotation marks that are on the on the team_name="Refugees" ??
and hopefully it will after just a tad more tweeking. I really do appreciate your help
---
heres snippets of the code from the scenario toplevel and the macro file i am editing the variable with
and hopefully it will after just a tad more tweeking. I really do appreciate your help
---
heres snippets of the code from the scenario toplevel and the macro file i am editing the variable with
Code: Select all
[side]
controller="human"
fog=yes
gold=100
hidden=no
income=-2
no_leader=no
share_vision="all"
shroud=yes
side=1
team_name=Refuges
user_team_name="Refuges"
[/side]
Code: Select all
#define LA_STARTING_BONUS_ECTOPLASM
##multiply ectoplasm points by the # of players IN PROGRESS
[store_side]
team_name=Refugees
variable=player_count
[/store_side]
{VARIABLE_OP la_devilry multiply $player_count.length}
{VARIABLE_OP la_devilry_per_turn multiply $player_count.length}
#{CLEAR_VARIABLE players}
#enddef
Last edited by LordAwsomeness on May 10th, 2018, 1:01 am, edited 1 time in total.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Re: How do you get a number and use it from sides having the same team name
the quotation marks shouldnt matter.. I hope you are refreshing your code with f5 after modifying? or restarting wesnoth...
In any case... if this simple thing doesn't work then use {FOREACH}... if you dont like to use {FOREACH} then read on how to use lua (https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides)... I doubt it will get deprecated... but it's more complicated than using WML...
---
So the team name doesnt match
In any case... if this simple thing doesn't work then use {FOREACH}... if you dont like to use {FOREACH} then read on how to use lua (https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides)... I doubt it will get deprecated... but it's more complicated than using WML...
---
Well then in first case you have team name "RefugLordAwsomeness wrote: ↑May 10th, 2018, 12:59 am heres snippets of the code from the scenario toplevel and the macro file i am editing the variable with
Code: Select all
[side] controller="human" fog=yes gold=100 hidden=no income=-2 no_leader=no share_vision="all" shroud=yes side=1 team_name=Refuges user_team_name="Refuges" [/side]
Code: Select all
#define LA_STARTING_BONUS_ECTOPLASM ##multiply ectoplasm points by the # of players IN PROGRESS [store_side] team_name=Refugees variable=player_count [/store_side] {VARIABLE_OP la_devilry multiply $player_count.length} {VARIABLE_OP la_devilry_per_turn multiply $player_count.length} #{CLEAR_VARIABLE players} #enddef
e
s" and then you are trying to filter it by using "Refugee
s"So the team name doesnt match
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
yea i always doenclave wrote: ↑May 10th, 2018, 1:02 am the quotation marks shouldnt matter.. I hope you are refreshing your code with f5 after modifying? or restarting wesnoth...
In any case... if this simple thing doesn't work then use {FOREACH}... if you dont like to use {FOREACH} then read on how to use lua (https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides)... I doubt it will get deprecated... but it's more complicated than using WML...
it is not deprecated yet. I know it is still usable. Imma try one more thing that you mentioned above that I missed though.
---
i think i just edited that when i copied and pasted after getting rid of the quotation marks. deleted an e in the process lol
---
nope I'm just blind thank you for you help! I have so many ways to try and make this work now i guessLordAwsomeness wrote: ↑May 10th, 2018, 1:08 ami think i just edited that when i copied and pasted after getting rid of the quotation marks. deleted an e in the process lol
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Re: How do you get a number and use it from sides having the same team name
Then you maybe need only 1 thing.. to add event when the multiplication happens...LordAwsomeness wrote: ↑May 10th, 2018, 1:08 ami think i just edited that when i copied and pasted after getting rid of the quotation marks. deleted an e in the process lol
Code: Select all
[event]
name=prestart
{LA_STARTING_BONUS_ECTOPLASM}
[/event]
Indeed don't worry it happens to me all the time too... 1 little letter.. or sign.. and nothing works;)LordAwsomeness wrote: ↑May 10th, 2018, 1:09 am I have so many ways to try and make this work now i guess
- LordAwsomeness
- Posts: 203
- Joined: August 12th, 2013, 2:20 pm
- Location: U.S.A.
Re: How do you get a number and use it from sides having the same team name
One more thing: do you perhaps know how to enable the ancient lich to advance from the lich?
Code: Select all
#ifdef ENABLE_ANCIENT_LICH
[advancefrom]
unit=Lich
experience=250
[/advancefrom]
#endif
and would i put it in the scenario toplevel?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Re: How do you get a number and use it from sides having the same team name
In MP you must never use [advancefrom]. You can use something like pre advance event to transform Lich to different type.
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: How do you get a number and use it from sides having the same team name
Guys, please edit your previous post instead of multiposting.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code