WML switch tag
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
WML switch tag
I think it would be useful to have a [switch] tag in WML, even it of couse could already be done with if tags.
I could work like that:
I could work like that:
Code: Select all
[switch]
[variable]
name=variable_name
[/variable]
[case]
value=1
#do something if variable_name equals 1
[/case]
[case]
value=2
#do something else if variable_name equals 2
[/case]
[/switch]
I was working on the proof of one of my poems all the morning, and took out a comma. In the afternoon I put it back again. -- Oscar Wilde
I agree with this, because it would eliminate the need for long chains of nested [if] statements required currently.
But, since [if] statements can do this also, it's a low priority.
But, since [if] statements can do this also, it's a low priority.
"ILLEGITIMIS NON CARBORUNDUM"
Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
You shouldn't need to nest [if]s to do this currently...
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
And I hate stupid people.
The World of Orbivm
Right- you should just do
if
then
endif
if
then
endif
...
Not a particularly profound point, but a notable one.
if
then
endif
if
then
endif
...
Not a particularly profound point, but a notable one.
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
And I hate stupid people.
The World of Orbivm
That's incompatible with else statements. Not else if, just plain old else. A switch usually allows for a default option (notably absent from the example) that handles the situation elegantly.turin wrote:Right- you should just do
if
then
endif
if
then
endif
...
Not a particularly profound point, but a notable one.
True - but what you can do is at the end have anNeoPhile wrote:That's incompatible with else statements. Not else if, just plain old else. A switch usually allows for a default option (notably absent from the example) that handles the situation elegantly.
Code: Select all
if
not1
not2
not3
then
endif
BTW, this isn't specific to this item - every new feature should be thought about in terms of whether it is worth doing given the specific values of these three costs.
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
And I hate stupid people.
The World of Orbivm
- Elvish_Pillager
- Posts: 8137
- Joined: May 28th, 2004, 10:21 am
- Location: Everywhere you think, nowhere you can possibly imagine.
- Contact:
This is doable with macros. You'd do:
Unfortuantely, I currently have no time to write the macros myself. Perhaps tomorrow.
Code: Select all
{SWITCH (var-name)}
{CASE (value)}
(commands)
{/CASE}
{CASE (value)}
(commands)
{/CASE}
{DEFAULT}
(commands)
{/DEFAULT}
{/SWITCH}
It's all fun and games until someone loses a lawsuit. Oh, and by the way, sending me private messages won't work. :/ If you must contact me, there's an e-mail address listed on the website in my profile.
Code: Select all
#define SWITCH VARIABLE
[set_variable]
name=switch
to_variable={VARIABLE}
[/set_variable]
[set_variable]
name=switch_done
value=no
[/set_variable]
#enddef
#define CASE VALUE
[if]
[variable]
name=switch
equals={VALUE}
[/variable]
[then]
[set_variable]
name=switch_done
value=yes
[/set_variable]
#enddef
#define /CASE
[/then]
[/if]
#enddef
#define DEFAULT
[if]
[variable]
name=switch_done
equals=no
[/variable]
[then]
#enddef
#define /DEFAULT
{/CASE}
#enddef
#define /SWITCH
#enddef
Just label them:
And they would be used like this:
Kind of bulky, but if it's really desired...
Code: Select all
#define SWITCH NUM VARIABLE
[set_variable]
name=switch{NUM}
to_variable={VARIABLE}
[/set_variable]
[set_variable]
name=switch_done{NUM}
value=no
[/set_variable]
#enddef
#define CASE NUM VALUE
[if]
[variable]
name=switch{NUM}
equals={VALUE}
[/variable]
[then]
[set_variable]
name=switch_done{NUM}
value=yes
[/set_variable]
#enddef
#define /CASE
[/then]
[/if]
#enddef
#define DEFAULT NUM
[if]
[variable]
name=switch_done{NUM}
equals=no
[/variable]
[then]
#enddef
#define /DEFAULT
{/CASE}
#enddef
#define /SWITCH
#enddef
Code: Select all
{SWITCH 1 (var-name)}
{CASE 1 (value)}
{SWITCH 2 (var-name)}
{CASE 2 (value)}
{/CASE}
{CASE 2 (value)}
(commands)
{/CASE}
{DEFAULT 2}
(commands)
{/DEFAULT}
{/SWITCH}
{/CASE}
{CASE 1 (value)}
(commands)
{/CASE}
{DEFAULT 1}
(commands)
{/DEFAULT}
{/SWITCH}
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
And I hate stupid people.
The World of Orbivm