Giving arrays variable names and values that are also variables

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
User avatar
Nyanyanyan
Posts: 21
Joined: May 11th, 2018, 10:40 pm

Giving arrays variable names and values that are also variables

Post by Nyanyanyan » April 16th, 2019, 12:01 pm

What I'm trying to do is making an array out of multiple variables, though for some reason using a variable as the name for the value in the array doesn't work and the game just saves the array as empty.
What I did and which isn't working:

Code: Select all

	
		{VARIABLE $newrebelleader "Id of the rebel leader"}
		[set_variables]
			name=capturedvillagestotal
			[value]
			x$newrebelleader=$leaderdeadsidevillages[$i].x
			y$newrebelleader=$leaderdeadsidevillages[$i].y
			[/value]
		[/set_variables]
$leaderdeadsidevillages[$i].x and y are just iterating over an array created by [store_villages], this whole thing being inside a FOREACH loop.

From my testing it seems that you simply can't use variables in the name for other variables created in this way.
Is there any way around this?
The whole point of this is trying to save which villages should belong to a certain leader that shares it's side with others, since to my knowledge, you can't save variables with locations, so my previous technique doesn't work here.
If there's an easier way to do this I'm all ears.

User avatar
Nyanyanyan
Posts: 21
Joined: May 11th, 2018, 10:40 pm

Re: Giving arrays variable names and values that are also variables

Post by Nyanyanyan » April 16th, 2019, 12:22 pm

Upon further testing I found out that the values of the id variables themselves are the problem.
A generic id would be something like 'Drake Blademaster-5'. Neither the space nor the - are compatible with the syntax from what I'm seeing.
Does anyone know of a way to circumvent this?

User avatar
Ravana
Moderator
Posts: 2024
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Giving arrays variable names and values that are also variables

Post by Ravana » April 16th, 2019, 3:01 pm

There are Lua solutions such as location sets https://wiki.wesnoth.org/LuaWML/Location_set

But WML variables are limited by WML syntax rules - they are in save file as WML, so only valid attribute names can be used.

You could do

Code: Select all

[value]
			x=$leaderdeadsidevillages[$i].x
			y=$leaderdeadsidevillages[$i].y
leader=$newrebelleader
			[/value]

User avatar
Nyanyanyan
Posts: 21
Joined: May 11th, 2018, 10:40 pm

Re: Giving arrays variable names and values that are also variables

Post by Nyanyanyan » April 16th, 2019, 9:39 pm

Ravana wrote:
April 16th, 2019, 3:01 pm
You could do

Code: Select all

[value]
			x=$leaderdeadsidevillages[$i].x
			y=$leaderdeadsidevillages[$i].y
leader=$newrebelleader
			[/value]
Thanks a lot, after a lot of debugging I got it to work as intended.

I uploaded the finished mod to the add-on server under "Revolution and Civil War" for anyone interested.

Atreides
Posts: 8
Joined: March 30th, 2019, 10:38 pm

Re: Giving arrays variable names and values that are also variables

Post by Atreides » Yesterday, 9:22 pm

Hi, just tried the mod and it gave an error (long) but the gist seems to be that side 99 is invalid when it tried to create rebel units. 99 is the default set by the mod but can be altered, should I try with a lower #? It's a neat idea.
--
Ya Hya Chouhada!

Post Reply