Python scripting

Discussion among members of the development team.

Moderators: Forum Moderators, Developers

Python scripting is a good idea?

WML is enough
12
57%
Not sure
6
29%
Python would be great
3
14%
 
Total votes: 21

Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

freecraft: actually I'm afraid you misunderstand me. :)

Let me clarify some points:

I don't think Python is 'garbage' for things like this. I knew Python, had used it for personal projects and commercially, and even worked with one of the developers of the popular Twisted Python.

Since I have a strong preference for static type checking [1], I wouldn't call Python my favorite language, but I appreciate its usefulness, its ease-of-use, and its relatively easy accessibility from system-level languages such as C and C++.

Now the important thing to understand about Wesnoth is that, like many software projects, it wasn't designed to be a certain way from the start. It started off as a very very small simple project. What is called WML today began as a simple configuration file. It slowly grew and features were added according to demands of users, and is now what it is today, with quite a few people who are skilled in using it to make campaigns, and a fairly large feature set.

Would Python be able to do the same sort of things? Almost certainly. But Python wasn't chosen, because when Wesnoth was started, I never imagined we'd end up with something so feature-rich that it'd support a complete events system.

So the question is, do we want to switch over to Python now? My answer is probably not. There is one big reason for this: it'd be alot of work, and we might end up with something that is disastrously full of bugs. Then we'd have to choose whether we wanted to continue trying to get all the bugs out, or revert the change. If we tried to get the bugs all out, we'd probably lose alot of users/credibility in the process, and some developers would likely become exhausted with the effort and leave the project and so forth.

And what would we get for this imho rather large risk? We could script a little more elegantly. Lots of scenario designers, who are usually, afaict not highly technical, would probably leave because they'd get frustrated at having to learn a completely new language and way of doing things. But, we could script a little more elegantly. Us programmers, who probably never actually write real scenarios, would love the capability to be able to write cool scripts, but the people who actually write scenarios wouldn't care.

I think one of the reasons Wesnoth has been successful is that it uses a philosophy of always trying to move forwards. We try to add new things, make the program better with each new release. We don't run around saying "we've been using technology x, but is technology y better? Maybe we should switch!"

That is expending alot of very valuable effort just to move sideways. We want to move forwards, not sideways. We don't have anywhere near the resources to move sideways all the time.

The only way I would entertain Python is if we could add it in an evolutionary fashion: add the capacity to augment WML with some Python in one release with very low effort -- something like silene's examples. Then perhaps bit by bit add more and more Python functionality, if people are finding it useful.

The important thing to understand about our current system is that it might not be pretty, but it works, and has served us well. To get us to change you'd be best served getting campaign designers actually wanting new features that are best implemented in Python.

David

[1] and yes, I do know about PyChecker
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming

freecraft
Posts: 94
Joined: April 28th, 2005, 12:49 am
Location: Serbia
Contact:

Post by freecraft »

I agree Dave ! I haven't missunderstood you.

As a solution, the only way for implementing python in evolutionary way, without too much work and without designers pissing off - is to add python tag in wml. Something like this:

Code: Select all

[scenario]
 [otherwmlstuff]
 ...
 [otherwmlstuff]
 
 [python]
  code = "
  python script as string here
  "
  trigger = unit_dies (or however you do this in wml)
 [/python]
[/scenario]
Writting this kind of scripts won't change current wml structure and both programmers and designers will have a nice harmony i think :) Although this is not what I have imagined when I started the topic, it looks enough.

Please, Dave, this is only idea, I'm not putting it in your source and I don't request from anybody to do it :) ...
Really, I agree with you. Well, bye !

User avatar
Elvish_Pillager
Posts: 8129
Joined: May 28th, 2004, 10:21 am
Location: Everywhere you think, nowhere you can possibly imagine.
Contact:

Post by Elvish_Pillager »

Hmm. That would be more like this:

Code: Select all

[scenario]
#scenario attributes & other WML & stuff
[event] #means "This happens at certain times"
name=die #describes those times
[filter]
side=1 #but it only happens when a unit on side one dies
[/filter]
[run_python] #this is the actual instruction
code="" #as you said here
[/run_python]
[/event]
[/scenario]
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.

freecraft
Posts: 94
Joined: April 28th, 2005, 12:49 am
Location: Serbia
Contact:

Post by freecraft »

Yep, thats it ... Currently I have wes 0.9.0 source on my computer, i will experiment with it, ofc, if i know enough to do such a thing. Looks like there is a huge code to read :I I will try to understand how engine works etc. and then to experiment something with my own tags and finally trying python.

Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

freecraft: if you want to start with something easy, yet rather useful, you might like to try this:

In mapgen.hpp there is the definition of an interface for creating maps. The game already has two map generators: default and cave.

What you might like to do is make a new map generator which takes a Python script as its argument and runs that script to produce a map.

This is the sort of thing that Python can probably do rather well, and there might be some people who'd be interested in writing Python map generators.

It's also something that'd probably be relatively easy to do, since you'd only have to touch a relatively small portion of Wesnoth code.

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

freecraft
Posts: 94
Joined: April 28th, 2005, 12:49 am
Location: Serbia
Contact:

Post by freecraft »

Thank you for your advice Dave, I hope I will get some free time after school to try that!

Invisible Philosopher
Posts: 873
Joined: July 4th, 2004, 9:14 pm
Location: My imagination
Contact:

Post by Invisible Philosopher »

Is it easy to prevent the Python from doing things? such as maliciously erasing your files?

The WML preprocessor is already pretty good at making up for the problems with plain WML.

Also, I have been working on coding a new preprocessor (i.e. new C++, same stuff in WML) that 'fixes' some things I consider bugs and adds a few things to make it more powerful. Unfortunately I have been having trouble with it. Though I got a working version,
  • With optimizations on, it took 25 seconds to preprocess the normal Wesnoth cfg files.
  • It didn't know enough about the origin of the result stuff, for telling the parser (to help error messages be useful).
  • I disliked part of my code's design.
So I'm still working on it in the time I have that's not taken by school. :|


About a Python random map generator, that seems cool... depending how versatile it is. Some places are very much good for map generation, especially anywhere with shroud, but the usual random map generators just aren't up to it. It does seem like something Python could do better than WML... if implemented properly. Although, it could be done with WML and extensive macros to get a pretty good system, such as is done with terrain graphics.

freecraft wrote:- EP, your example of function calling is evil, hack and althought it may work, I don't like stuff like that ...
True, if I get enough time I may look into less "hackish" approaches to many WML incompletenesses.
freecraft wrote:It is not readable?
It is readable, because of the encapsulation it exhibits. The macro users need not know of the hacky system. (although the NAMEs should be prefixed with something inside the macro, so they don't accidentally collide with real descriptions, but that still doesn't affect users.)
Play a Silver Mage in the Wesvoid campaign.

Post Reply