WML idea: implementation of the [class] and [function] tags

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
Post Reply
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

WML idea: implementation of the [class] and [function] tags

Post by toms »

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:

Code: Select all

[class]
name="sample_class"
 [members]
 xxx=yyy
 aaa=bbb
 [members]
[/class]
And it's used this way:

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

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

Code: Select all

[scenario]
...
[event]
[function]
name=sample_class.sample_function
arguments=$foo,$bar
[/function]
...
A function could also be a standalone function outside a class.
First read, then think. Read again, think again. And then post!
CarpeGuitarrem
Posts: 250
Joined: November 19th, 2007, 7:46 pm
Location: One among the Fence

Post by CarpeGuitarrem »

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
CIB
Code Contributor
Posts: 625
Joined: November 24th, 2006, 11:26 pm

Post by CIB »

CarpeGuitarrem wrote:Sounds like it wouldn't be too hard to implement, considering it's a practically direct port from C++...
C++ has no eval, so..
User avatar
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Post by Noyga »

Well you can already initialize variables like this :

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]
This defines :
$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
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Noyga wrote:Well you can already initialize variables like this (...)
I see.

But I think that [function] (described above) is useful anyway.
First read, then think. Read again, think again. And then post!
PingPangQui
Posts: 267
Joined: July 18th, 2006, 11:52 am

Post by PingPangQui »

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.

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]
The following doesn't give any output for Char.Name as if the variable wasn't there.It just tells "Your name is ".

Code: Select all

...
message=_"Your name is $Char.Name"
...
the same applies for

Code: Select all

...
message=_"Your name is $Char[0].Name"
...
Do you have any idea what could be wrong?

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.
User avatar
Mist
Inactive Developer
Posts: 753
Joined: February 15th, 2007, 8:44 am
Location: Milton Keynes, UK

Post by Mist »

[+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.
Somewhere, between the sacred silence and sleep.
Disorder.
PingPangQui
Posts: 267
Joined: July 18th, 2006, 11:52 am

Post by PingPangQui »

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.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Back to topic please: Is there any interest in this idea(s)?
First read, then think. Read again, think again. And then post!
aManFromMars
Posts: 2
Joined: January 23rd, 2008, 8:14 pm

Post by aManFromMars »

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.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

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.
I don't remember me asking for spam in this thread. :evil:
First read, then think. Read again, think again. And then post!
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

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