Programing language

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:
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Programing language

Post by Dave »

ivan wrote:
Dave wrote: Actually it is. It's much easier than maintaining Python bindings in my view.
But we already have Python bindings for core C++ objects (team, unit, map) and, in fact, Python interpreter is already inside Wesnoth executable.
Uh-huh. I've said before that I'm fine with Python being used in places it makes sense, and for more parts of the game to have support for Python scripting. In fact, I think a great place to start would be to allow random map generation using a Python script.
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
ivan
Posts: 15
Joined: April 28th, 2008, 12:42 pm

Re: Programing language

Post by ivan »

I've just found that I want to type 'svn ci' to remember current state before further experimentation..

Can we have a branch? Or shall I do it somewhere else?

EDIT: here's the diff of what I have as a starting point http://dpaste.com/hold/90630/ nothing special, yet.
Soliton
Site Administrator
Posts: 1732
Joined: April 5th, 2005, 3:25 pm
Location: #wesnoth-mp

Re: Programing language

Post by Soliton »

ivan wrote:Can we have a branch? Or shall I do it somewhere else?
A branch sounds like a good idea. Best to ask on IRC in #wesnoth-dev on freenode for further help/instructions.
"If gameplay requires it, they can be made to live on Venus." -- scott
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Programing language

Post by Sapient »

uzytkownik wrote: As WML is turing-complete AFAIK you can write any algorithm in it.
It doesn't matter much, but FYI there is a limit of 65K loop iterations in WML. This concept that WML should limit iterations to guarantee a halt means (in principle at least) that it is not a Turing-complete language. There are currently some ways of working around it by using events that fire other events. Eventually we may "fix" that workaround.

http://en.wikipedia.org/wiki/Turing_completeness
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

What with:

Code: Select all

# Lots of WML Code
  [python]
     # Python
  [/python]
# Even more WML Code
Sapient wrote:
uzytkownik wrote: As WML is turing-complete AFAIK you can write any algorithm in it.
It doesn't matter much, but FYI there is a limit of 65K loop iterations in WML. This concept that WML should limit iterations to guarantee a halt means (in principle at least) that it is not a Turing-complete language. There are currently some ways of working around it by using events that fire other events. Eventually we may "fix" that workaround.

http://en.wikipedia.org/wiki/Turing_completeness
<HUMOR>WML is turing complete. Implementation is not ;)</HUMOR>

C++ templates are usually described as TC despite that thay have similar limitations.

PS. Sorry for late response - I haven't got mail/miss it for some reason.
ivan
Posts: 15
Joined: April 28th, 2008, 12:42 pm

Re: Programing language

Post by ivan »

uzytkownik wrote:What with:

Code: Select all

# Lots of WML Code
  [python]
     # Python
  [/python]
# Even more WML Code
I think it makes more sense to add 'script' attribute to some WML tags. And keep python scripts separately.
Like

Code: Select all

[event]
name=die
script=MyCampaignName.scripts.events.on_leader_die
[/event]
When on_leader_die is a Python callable inside events.py inside scripts directory inside MyCampaignName directory
mattyp
Posts: 2
Joined: December 14th, 2008, 8:43 pm

Re: Programing language

Post by mattyp »

First off, I have very little knowledge of C/C++, the source code for BfW, or things like compilers and interpreters. So take what I say with a grain of salt.

The way I see it, open source projects are meant for stuff like this. Maybe one of you who wants a real scripting language can begin implementing it in a separate from the main development of the game. The more people that care about it, the more people will join once something gets started. Once it's sufficiently complete, the see about adding it into the main part of the game.

I see no reason why there can't be two different content writing languages. There could be the "simple" wml and the "advanced" whateverscript. When the game reads a particular file, it can determine what type of content it is, and then use the appropriate compiler/interpreter for that particular file.
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Re: Programing language

Post by Viliam »

mattyp wrote:I see no reason why there can't be two different content writing languages.
I guess the game code could be (maybe already is) divided to a "scripting language API" and "WML interpreter", and the second one could be replaced or used alternatively with another interpreter (if someone will contribute the code). Adding a new interpreter might be considered "feature creep", but dividing the program into scripting API and scripting interpreter is just a refactoring which IMHO does not any harm.

Then, the alternative language proponents would have their turn. It would be their task to make a new Wesnoth version with added interpreter of another language. And then someone would have to make a new interesting content using a new interpreted language, to "prove" that the change adds value to the game. -- Because if adding another interpreted language would not show improvement in game content, then probably the WML was good enough for content authors, and the change does not improve situation for content authors, maybe the alternative is even worse for them.

I think this would be the reasonable solution for current situation. Wesnoth developers should make adding new interpreted language possible. But the remaining work should be left on new language proponents. Only if they are able to provide the code and content, then their idea is worth including in the game. If there is no one willing to design and support the new language, or if there is no one willing to write content using the new language, then the idea seems interesting on the surface, but in reality does not work. We need to remember that people complaining about WML are usually programmers, but a typical content author may see things very differently. And the scripting language should be made convenient for content authors. This is a part of Wesnoth popularity -- relatively easy content making, even for people with no programming skills.
Ferk
Posts: 6
Joined: December 19th, 2008, 9:55 pm

Re: Programing language

Post by Ferk »

I'm relatively new to Wesnoth and I'm not at all familiar with WML, but... I would like to point out the capabilities the scheme (simple lisp dialect), which I think it would be a language that really suits this purpose.

I don't think that it would be hard at all for non-programmers to understand scheme if they were able to understand WML.

Code: Select all

(side
    (side 4)
    (controller ai)
    (team_name dwarves)
    (user_team_name Dwarves)
    
    (type Elvish Marshal)
    (description Lerel)
    (user_description "Lerel")
    (canrecruit 't)
    
    (recruit "Elvish Archer" "Elvish Fighter" "Elvish Scout" "Elvish Shaman")
    
    (GOLD 300 200 100)
    
    (ai
      (recruitment_pattern fighter archer archer archer scout)
    )
)
I think it has the benefits of markup languages and all the power of programming languages, abstraction layers and automation of simple tasks by using functions and conditionals efficiently.

The GNU Guile scheme interpreter has been the recommended extension language by the FSF for many years.
AI
Inactive Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Programing language

Post by AI »

While it seems more readable to the average non-programmer than LUA or the like (except for the 't, probably means 'true', but why the single quote?), the same thing applies as with all "let's replace/supplement WML with something else" ideas: show us the code, then we'll talk. ;)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Programing language

Post by Sapient »

I'll admit that your Scheme example does look beautiful to a programmer, as far as syntax goes. I do believe that if we offered this language as a possibility then people who mastered this language-- and used a suitable editor-- would prefer it over WML. However, there is a tradeoff here (other than the obvious implementation and maintenance time involved); newcomers to programming aren't fond of the Lots of Insidious Sets of Parenthesis.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

AI wrote:While it seems more readable to the average non-programmer than LUA or the like (except for the 't, probably means 'true', but why the single quote?), the same thing applies as with all "let's replace/supplement WML with something else" ideas: show us the code, then we'll talk. ;)
I guess scripting might be slightly more confusing for those who do not know RPN (or PN):

Code: Select all

(set_gold 1 (+ (* 2 var) 4))
But - well WML is much more confusing:

Code: Select all

{SET_VARIABLE var_tmp $var}
{VARIABLE_OP var_tmp multiply 2}
{VARIABLE_OP var_tmp add 4}
[set_gold]
  side=1
  amount=$var_tmp
[/set_gold]
Last edited by uzytkownik on December 20th, 2008, 4:32 pm, edited 2 times in total.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Programing language

Post by Sapient »

your example is not even valid WML... but I think shortcut macros which only save you from typing one or two lines should be avoided by people who are first learning WML.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

Sapient wrote:your example is not even valid WML... but I think shortcut macros which only save you from typing one or two lines should be avoided by people who are first learning WML.
Ok.

1. I counted 3 errors - mul instead multiply, typo of var instead of var_tmp and tag set_gold which I created just to simplyfy it. The first two will be fixed in a minute.

Full, 'correct' WML solution (written mainly from memory):

Code: Select all

[set_variable]
  name=var_tmp
  value=$var
[/set_variable]
[set_variable]
  name=var_tmp
  multiply=2
[/set_variable]
[set_variable]
  name=var_tmp
  add=4
[/set_variable]
[store_gold]
  side=1
[/store_gold]
[set_variable]
  name=gold
  multiply=-1
[/set_variable]
[set_variable]
  name=var_tmp
  add=gold
[/set_variable]
[gold]
  side=1
  amount=$var_tmp
[/gold]
[clear_variable]
  name=var_tmp
[/clear_variable]
[clear_variable]
  name=gold
[/clear_variable]

Code: Select all

{VARIABLE var_tmp $tmp}
{VARIABLE_OP var_tmp multiply 2}
{VARIABLE_OP var_tmp add 4}
[store_gold]
  side=1
[/store_gold]
{VARIABLE_OP gold multiply -1}
{VARIABLE_OP var_tmp add gold}
[gold]
  side=1
  amount=$var_tmp
[/gold]
{CLEAR_VARIABLE var_tmp}
{CLEAR_VARIABLE gold}

Code: Select all

(gold 1 (+ (* var 2) 4 (- (get_gold 1))))
2. How does it change my point? I feel that part of the LISP/Scheme syntax may be unfamilliar for people who do not know what is RPN or PN (actually LISP/Scheme is in Polish Notation). However it is still much more HL and familiar then NSSA (non-static single assigment ;) ) in WML.

I'd like to have LISP/Scheme as a scripting language for wesnoth but I'm worried if it's scripting will not be harder for newcommers then in for example python. Although I feel it will be much easier then in WML.

3. Verbose redundancy to some extend make code unclear. If I can see the whole event/procedure in one screen (80x24 is quite good 'memory' size) it is so simpler to debug. If a line is a logical steps it is much easier to follow it than if the single step in on 20 lines.
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Programing language

Post by Dave »

I think the biggest thing people overlook with comparisons is that the primary purpose of WML is not to manipulate variables in sophisticated ways like a typical programming language does all the time. Doing that in WML is indeed tedious.

The main purpose of WML is to act as a data language for Wesnoth scenarios. As part of this, it may on occasion be used to perform some limited variable manipulation, but this should not be common place in comparison to its main uses.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Post Reply