Ok, that’s a nice trick. It’s much closer to an ideal in the terms of source code readability. It won’t work for a real class (non-sigleton), but that is much more common in library than in user’s game. Another possible little trick would be to simplify entering aliases by writing something like aliases = ‘small, brass, hook, peg’ and let the engine parse it into an array internally.
My Python skills are pretty rusty, but in Ruby you can do something like this:
Looks like the Pyf engine written in python uses XML files to help create locations and perhaps objects. I’m unsure that would be necessary or really add any gain though. You will still need to program the game logic, so you will still be in code anyway. May was well just define objects in the code. Much less writing than the XML anyway. And I’d think YAML would be more appropriate than XML for readability, though I suppose YAML was not in wide use at the time.
Well, at my house, coffee is black and data is JSON. Other versions you need to ask for. Just sayin’.
well i do like cream maybe thats why
I’ve been prototyping a framework, codenamed pyphiverses, with python. Very crude right now, because an IF system is complex by nature.
The thing is so complex that some parts are full projects on its own. Parser, world model, time model, action model, multiplatform/web player front-ends, authoring tools, etc…
I think that good foundations are needed before ironing out some syntax. Sugar it’s just the tip of the iceberg. An important tip, sure, because it’s what authors will face with, but you need much, much more before and under it.
My utopian view it’s a modular system that can be adapted to several philosophies, not just because different languages need different parsers (even parser-less), or because singleplayer turn based is a different beast to turn or realtime multiplayer. Room modeling is not the only option, and so on…
This modular framework and some libraries (stress-testing the framework) implementing the known-to-work models, inspired by the actual systems, will be a perfect first milestone.
Then (even before), it may be used to drive and promote innovation in IF, which is the main goal. Using a general purpose language “batteries included” helps in this regard, I think.
This project it’s so ambitious that I even lost focus sometimes, but I’m determined to work on this multipurpuse system. Lately I’m thinking on using the Raspberry Pi as the main platform.
Any help or advice are welcomed. I’m working under the premise of libre software.
What foundations do you think are essential for a system like this?
I am also thinking about writing an IF story and I don’t know if I would be better off learning inform or authoring it in python. I am not seeking to create a new IF system. I know how to write a good parser thanks to a class in natural language processing. I can think of all sorts of cool things I can do in python (attach functions in a dictionary to various uses of an object for instance, or have a variable time cost associated with moving from location to location).
Is what I get with inform worth the effort of learning a new language versus creating my own system in python? Is it possible in inform to lets say have a bus object appear in a location every so many game minutes? Then have the player enter a bus location where the exits would be ‘get off’ or ‘next stop’? and then cycle through all the possible stops?
Sure, that’s standard IF fare. (No pun intended.) Any of the major systems can do that.
Although you’re going to wind up in a design discussion about whether “next stop” is a reasonable IF command. (“Wait” would be traditional, or perhaps a notion of locations such that “go to Croydon” works.)
Yes, it’s definitely possible. But I don’t know which system this would be easiest in. Take a look at these I7 examples: http://inform7.com/learn/man/Rdoc64.html
Edit: Dammit, I got zarf’d. Still, the link should be helpful.
Also: IF was conventionalized before natural language parsing was a serious subject. (Sure, Eliza, but not really.) I suspect that if you start with what you know, you will be inventing a new IF idiom from scratch. Could be interesting; will definitely be a lot of work.
Sorry for auto-quoting
A recent thread stated part of my question much better than I did, and got several educated responses. Just for the record: Fundamental concepts of a world model?
I probably should have looked here and found this thread first, but I was thinking about syntax for a Python based IF authoring system lately, and wrote up this post.
It looks like I have independently duplicated the idea of automatically instantiating classes. This is the one thing I’ve already writen code for; it wasn’t too hard. Writing an entire library and everything else that an IF system needs is the hard part, of course.
hey two-star, interesting blog post. Yeah I think you definitely need to solve the forward reference problem somehow. Does modifying the AST mean you give the IF source to a Python program to generate bytecode? Why not go farther, write the Python IF source as something more like a literate program, with the prose as the IF prose interleaved with conventional Python syntax?
Dealing with the AST means that Python handles all the parsing for you – as long as your format looks like syntactically valid Python. This is a very nice shortcut (which I made use of in Seltani, for example).
If you want to define a format which is a mix of Python and something else, then you’re back to the job of parsing it yourself.
I think the problem with using python like that is that you have to be prepared to handle ANY python language or library construct that the parser will happily accept for you.
If you want a python-like DSL I think there is a parser in the standard libs somewhere. Of course then you have to write a lot of code to handle simple things like conditionals and loops.
This is why LISP was invevted I guess. Not that I do not love python, but something like Clojure is much better suited for repurposing as a DSL.
No you don’t. You can do anything you want with the AST. (Also, Python libraries can’t define new syntax. It’s only what the core language defines.)
For my project I implemented a subset of Python (with some semantic changes as appropriate). I didn’t want to deal with exception handling, so I didn’t implement it. If the user enters a “try: except:” statement, he gets an error back.
Basically, what zarf said. The IF source is (or should be) syntactically valid Python that would encounter problems at run time as it stands, so we use the ast module to massage it into different valid Python that does what we want it to do. The reason we don’t just write the IF source that way in the first place is that it would be verbose and ugly. The IF source (as I envision it) is Python, and the Python interpreter will handle it, with the help of ast tricks, (and metaclass tricks, and operator overloading tricks.) That’s assuming I can get the ast hacks to do what I want. I’m still a little fuzzy on that, but I’m pretty hopeful.
Ok, if you do AST tricks first to verify that the script does nothing unexpected I guess you can use the python interpreter, but how easy is that? Is there for instance a stable sandboxed python yet? Using python to parse a python-like script to a AST is very different from running something as python.
If you really do something clever with the AST you could start with replacing the class semantics/keyword with something that better fits the DSL.
Hmmm, I have a new point of view. I discover python can better suit other language, like Chinese. most recently I tried “intficpy”, it very good dispose Chinese words. But misfortune is its don’t have good instructional.
Did you also discover Balladeer?
It’s mentioned in several threads on this forum, as well as being on GitHub, PyPI and IFWiki.
I’d be interested to learn how easy it is to find for those who are looking for such a thing.