How do you get a number and use it from sides having the same team name

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
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

Post by LordAwsomeness »

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
User avatar
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

Post by Pentarctagon »

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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: How do you get a number and use it from sides having the same team name

Post by enclave »

LordAwsomeness wrote: May 9th, 2018, 11:42 pm

Code: Select all

[store_side]
	team_name=Refugees
	variable=player_count
[/store_side]
This will store ONLY sides with team name "Refugees"...
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]
Then you could foreach.. like so

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}
But I have no idea what you think you will be able to do with la_devilry... maybe then you want to do:

Code: Select all

[modify_side]
side=2
gold=$la_devilry
[/modify_side]
Or maybe you wanted to change team gold like so:

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]
I hope something can help you!
User avatar
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

Post by LordAwsomeness »

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.

enclave wrote: May 10th, 2018, 12:06 am

Code: Select all

[store_side]
	team_name=Refugees
	variable=player_count
[/store_side]
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.
- 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
User avatar
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

Post by LordAwsomeness »

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}
How would I use the array to get the number of side/players with the team_name=refugees?
- 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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: How do you get a number and use it from sides having the same team name

Post by enclave »

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.
Then you probably only need to do:

Code: Select all

[store_side]
	team_name=Refugees
	variable=player_count
[/store_side]
{VARIABLE_OP la_devilry multiply $player_count.length}
Keep in mind it may be 0, then la_devilry may be 0 too... whatever it is..
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.
User avatar
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

Post by LordAwsomeness »

enclave wrote: May 10th, 2018, 12:42 am Then you probably only need to do:

Code: Select all

[store_side]
	team_name=Refugees
	variable=player_count
[/store_side]
{VARIABLE_OP la_devilry multiply $player_count.length}
Keep in mind it may be 0, then la_devilry may be 0 too... whatever it is..
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.
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.
- 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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: How do you get a number and use it from sides having the same team name

Post by enclave »

It may be "user_team_name" (the one that shows for you... the real name may be different)
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}
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..
User avatar
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

Post by LordAwsomeness »

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

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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: How do you get a number and use it from sides having the same team name

Post by enclave »

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...

---
LordAwsomeness 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
Well then in first case you have team name "Refuges" and then you are trying to filter it by using "Refugees"
So the team name doesnt match :)
User avatar
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

Post by LordAwsomeness »

enclave 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...
yea i always do :)
it is not deprecated yet. I know it is still usable. Imma try one more thing that you mentioned above that I missed though.

---
enclave wrote: May 10th, 2018, 1:04 am
Well then in first case you have team name "Refuges" and then you are trying to filter it by using "Refugees"
So the team name doesnt match :)
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

---
LordAwsomeness wrote: May 10th, 2018, 1:08 am
enclave wrote: May 10th, 2018, 1:04 am
Well then in first case you have team name "Refuges" and then you are trying to filter it by using "Refugees"
So the team name doesnt match :)
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 :doh: thank you for you help! I have so many ways to try and make this work now i guess :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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: How do you get a number and use it from sides having the same team name

Post by enclave »

LordAwsomeness wrote: May 10th, 2018, 1:08 am
enclave wrote: May 10th, 2018, 1:04 am
Well then in first case you have team name "Refuges" and then you are trying to filter it by using "Refugees"
So the team name doesnt match :)
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
Then you maybe need only 1 thing.. to add event when the multiplication happens...

Code: Select all

[event]
name=prestart
{LA_STARTING_BONUS_ECTOPLASM}
[/event]
---
LordAwsomeness wrote: May 10th, 2018, 1:09 am I have so many ways to try and make this work now i guess :lol:
Indeed ;) don't worry it happens to me all the time too... 1 little letter.. or sign.. and nothing works;)
User avatar
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

Post by LordAwsomeness »

enclave wrote: May 10th, 2018, 1:12 am Indeed ;) don't worry it happens to me all the time too... 1 little letter.. or sign.. and nothing works;)
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
this is in the code but i am not quite sure how to execute with a #ifdef
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
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: How do you get a number and use it from sides having the same team name

Post by Ravana »

In MP you must never use [advancefrom]. You can use something like pre advance event to transform Lich to different type.
User avatar
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

Post by Pentarctagon »

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
Post Reply