Listing the units on a side

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
Anyar
Posts: 191
Joined: July 25th, 2005, 9:18 pm
Location: MI

Listing the units on a side

Post by Anyar »

I want to know whether or not it is possible to use WML to store a sides units(other than the leader) into variables, then set those units as options in a menu. The main problem I have with this is getting the number of units a side has, and then having the menu list the units.

I need this is for an mp scenario, which has a structure somewhat like this:
Two players who have to beat an ai enemy 3 times, while being unable to recruit(having only a small army fitted to the particular leader they chose), but recieving reinforcements and access to shops containing upgrades and healing, then after completing this, get too choose from their units 4 which they want to take to a final round, in which they battle the other human player to win the game. If they do not have 4, or for some reason do not want any of their troops, they will recieve random units.

I know that the first part(storing the units) could be done via store unit with a filter to select all the units of the side, but I don't know how I would go about adding these as menu options for the player to select. Can someone please tell me whether this is possible, and if so, how would I do it?
Even as the fingers of the two hands are equal, so are human beings equal to one another. No one has any right, nor any preference to claim over another. You are brothers. - Muhammed
scott
Posts: 5243
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Post by scott »

It might be possible to store all the WML required to build the option menu into a single variable then pass the value of the variable as an argument of a macro, but I don't think the pain would be worth it.
Hope springs eternal.
Wesnoth acronym guide.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

I really doubt what scott suggested would work... the variable would never be expanded.



Since Option cannot take a variable number of options, you would have to do something like this:

Menu 1. Choose level of unit.
Menu 2. Choose type of unit/go back.
Menu 3. Is it one of these 5 units?/no/go back
Menu 4. One of these 5?/no/go back
etc...
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
scott
Posts: 5243
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Post by scott »

turin wrote:I really doubt what scott suggested would work... the variable would never be expanded.
This is what I tried:

Code: Select all

#define EXECUTE_CODE VAR
{VAR}
#enddef

[event]
name=turn 2

{VARIABLE code_2_exe ("[unit]
side=1
x,y=10,10
type=Spearman
[/unit]")}

{EXECUTE_CODE $code_2_exe}

[/event]
It choked on the variable substitution ( {VAR} ) sitting on a line by itself.
Hope springs eternal.
Wesnoth acronym guide.
Dacyn
Posts: 1855
Joined: May 1st, 2004, 9:34 am
Location: Texas

Post by Dacyn »

scott wrote:This is what I tried:

Code: Select all

#define EXECUTE_CODE VAR
{VAR}
#enddef[/quote]
What you have to remember is that WML is processed into pseudo-WML code before actually being used in-game... After that, keys and tags don't mean anything. In other words, strings which happen to contain keys are completely unrelated to the keys themselves...
Anyar
Posts: 191
Joined: July 25th, 2005, 9:18 pm
Location: MI

Post by Anyar »

OK, after reading this,am I correct in saying that what I want is impossible/extremely hard to to do atm?
Because of this, I can probably use a simpler approach, because the scenario is set up with every leader having the same size army(9 units other than leader), and the problem of the reinforcements changing this number can be solved by placing them under command of an ai. So, using this, could I store the units in an array and have the variables for each of the 9 units set as options? Also, what is the syntax for using a variable from an array(I didn't understand how to use them after looking at the wiki page)?
Even as the fingers of the two hands are equal, so are human beings equal to one another. No one has any right, nor any preference to claim over another. You are brothers. - Muhammed
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

It shouldn't be that hard really, the main limitation is that your option menu cannot contain an arbitrarily long list. In other words, you will have to allow the user to choose from (to use turin's example) five or so units at a time, or proceed to the next five.

If you want to filter these units based on choices of level or type, that is another possibility, but not mandatory.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply