WML idea: implementation of the [class] and [function] tags
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 idea: implementation of the [class] and [function] tags
Yes, I really mean WML tags enable something like object-orientated WML.
I come up with a concept too. The classes are defined in an extra .cfg file.
They could look like this:
And it's used this way:
The name is unique and used for identification. yyy is the default value of the meber xxx. Same for aaa and bbb.
But this could be even more:
Here, the [members] are nested. The members are now:
sample_class.xxx
sample_class.xxx.sub_xxx
sample_class.aaa
Also, the second new tag is used: [function]
This sample function simply multiplies the two arguments. The returned value can be accessed via $sample_class.sample_function.return
A function should also be able to have access to its own members. IMO this should simply be the name of the member. In this case, it could be xxx, xxx.sub_xxx, aaa.
A function is used that way:
A function could also be a standalone function outside a class.
I come up with a concept too. The classes are defined in an extra .cfg file.
They could look like this:
Code: Select all
[class]
name="sample_class"
[members]
xxx=yyy
aaa=bbb
[members]
[/class]
Code: Select all
#initialize a foo object that has the class "sample_class"
[set_variable]
name=foo
class=sample_class
[/set_variable]
#change the value of [i]sample_class.xxx[/i]
[set_variable]
name=sample_class.xxx
value=1
[/set_variable]
But this could be even more:
Code: Select all
[class]
name=sample_class
[members]
xxx=yyy
[members]
sub_xxx=2
[/members]
aaa=bbb
[/members]
[function]
name=sample_function
arguments=2
[set_variable]
name=return
value=$arg[0]
[/set_variable]
{VARIABLE_OP return multiply $arg[1]}
[/function]
[/class]
sample_class.xxx
sample_class.xxx.sub_xxx
sample_class.aaa
Also, the second new tag is used: [function]
This sample function simply multiplies the two arguments. The returned value can be accessed via $sample_class.sample_function.return
A function should also be able to have access to its own members. IMO this should simply be the name of the member. In this case, it could be xxx, xxx.sub_xxx, aaa.
A function is used that way:
Code: Select all
[scenario]
...
[event]
[function]
name=sample_class.sample_function
arguments=$foo,$bar
[/function]
...
First read, then think. Read again, think again. And then post!
-
- Posts: 250
- Joined: November 19th, 2007, 7:46 pm
- Location: One among the Fence
Sounds like it wouldn't be too hard to implement, considering it's a practically direct port from C++...
Glory in Blood...Needs Programming Help!
If you have time, check out my ongoing serial story...
The Hidden: Secrets of the Future's Past
If you have time, check out my ongoing serial story...
The Hidden: Secrets of the Future's Past
Well you can already initialize variables like this :
This defines :
$group[1].monster[1].name=Yeti
$group[1].terrain=FHS
$group[2].monster[3].name=Skeleton
Code: Select all
[+variables]
[group]
[monster]
name=Yeti
[/monster]
terrain=FHS
[/group]
[group]
[monster]
name=Giant Spider
[/monster]
[monster]
name=Giant Scorpion
[/monster]
[monster]
name=Skeleton
[/monster]
terrain=dIJfT
[/group]
[/variables]
$group[1].monster[1].name=Yeti
$group[1].terrain=FHS
$group[2].monster[3].name=Skeleton
"Ooh, man, my mage had a 30% chance to miss, but he still managed to hit! Awesome!" -- xtifr
-
- Posts: 267
- Joined: July 18th, 2006, 11:52 am
Hi Noyga,
i've just tried that out. However sth. does seem to work. Though there aren't any error messages it just seems to ignore my variable initialisation.
The following doesn't give any output for Char.Name as if the variable wasn't there.It just tells "Your name is ".
the same applies for
Do you have any idea what could be wrong?
Alternatively, could I define a record also like this?
At least it seems to work like this. Not sure if it is correct though.
PingPangQui
P.S.: What is the purpose of the + in [+variables].? There doesn't seem to be a difference if I just write [variables] so far. Or what's the difference between [+variables] and [variables]?
i've just tried that out. However sth. does seem to work. Though there aren't any error messages it just seems to ignore my variable initialisation.
Code: Select all
[+variables]
[Char]
Name=snoopy
Folk=elve
Alignment=neutral
Gender=male
Class=warrior
Unit=elvish_fighter
[Trait]
First=strong
Secound=resilient
[/Trait]
[/Char]
[/variables]
Code: Select all
...
message=_"Your name is $Char.Name"
...
Code: Select all
...
message=_"Your name is $Char[0].Name"
...
Alternatively, could I define a record also like this?
Code: Select all
{VARIABLE Char.Name snoopy}
{VARIABLE Char.Folk elve}
{VARIABLE Char.Alignment neutral}
...
At least it seems to work like this. Not sure if it is correct though.
PingPangQui
P.S.: What is the purpose of the + in [+variables].? There doesn't seem to be a difference if I just write [variables] so far. Or what's the difference between [+variables] and [variables]?
The Clan Antagonist.
"Larry the Cow was a bit frustrated at the current state of Linux distributions (...) until he tried Gentoo Linux" - Free Software for free people.
"Larry the Cow was a bit frustrated at the current state of Linux distributions (...) until he tried Gentoo Linux" - Free Software for free people.
[+variables] is supposed to add a list of new variables to existing ones in the same way as [+units] works for unit definitions.
[variables] is a gamestate only tag used to inform the game that following lines of text are to be treated as variables.
There are few problems with example given by Noyga mostly resulting from the fact that [variables] is used in many places troughout the gamestate (each unit has it's own [variables] section) and [+tag] allways adds data to the last occurence of the tag. If you want more details read
http://www.wesnoth.org/wiki/SyntaxWML
And yes, your definition of container is correct.
[variables] is a gamestate only tag used to inform the game that following lines of text are to be treated as variables.
There are few problems with example given by Noyga mostly resulting from the fact that [variables] is used in many places troughout the gamestate (each unit has it's own [variables] section) and [+tag] allways adds data to the last occurence of the tag. If you want more details read
http://www.wesnoth.org/wiki/SyntaxWML
And yes, your definition of container is correct.
Somewhere, between the sacred silence and sleep.
Disorder.
Disorder.
-
- Posts: 267
- Joined: July 18th, 2006, 11:52 am
Thanks Mist. That helped .
The Clan Antagonist.
"Larry the Cow was a bit frustrated at the current state of Linux distributions (...) until he tried Gentoo Linux" - Free Software for free people.
"Larry the Cow was a bit frustrated at the current state of Linux distributions (...) until he tried Gentoo Linux" - Free Software for free people.
-
- Posts: 2
- Joined: January 23rd, 2008, 8:14 pm
I don't remember me asking for spam in this thread.aManFromMars wrote:No mention there, Toms, about the Virtual Template Macro .....and ITs NEUKlearer VariableActivity ....AI Colossal Astuteness.
An objectOriented Card Play Gambit, in All Probability, Probably.
First read, then think. Read again, think again. And then post!
I proposed a similar idea but the problem with functions in WML is you first have to figure out how to reference nonscalar arguments within the function body (i.e. how to cleanly insert tags that have been passed-in, such as [filter] arguments).
You can easily make functions in WML, but until you solve that problem, they won't really be that useful. It's not an easy problem to solve, unfortunately.
You can easily make functions in WML, but until you solve that problem, they won't really be that useful. It's not an easy problem to solve, unfortunately.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."