Public development version of Galaxia Reborn

<![CDATA[The current version of Galaxia Reborn is now available to play with. You can't actually do that much but some things are still fun to play with.

Signup works but doesn't actually give you anything you can use so just login as "Q" with password "q".

You can move ships around and build more at the colony (you have to find the colony first though :P) although you can't send them into space just yet. Also, the entire interface has been translated into Finnish (well almost. Two little bits were added afterwards but they'll get done soon enough). Thanks for that go to my girlfriend Julia. If anyone is interested in translating the interface into a different language let me know . You’ll get a permanent link on the info panel at the bottom for people using your language as well as a mention in any credits.

Galaxia Reborn]]>

Galaxia, PHP

Wohoo, MySQL 4!

<![CDATA[Not that it really makes much difference yet, I'm now running MySQL 4! The upgrade was easier than I expected with the only problem not strictly being an upgrade problem (I had to manually kill MySQL and restart it to get it to recreate my socket file).

This is all preparation for installing PHP5 so everyone can actually see Galaxia Reborn 🙂

php5, mysql, apache]]>

Galaxia, OpenID

OpenID in GR

Well I have OpenID working at a basic level in Galaxia for signing up and logging in. For signups though a user still needs to provide a username eventually to replace the url which will generally be too long…

Galaxia, PHP

Scripting in Galaxia Reborn

<![CDATA[Introduction to XGS

This won’t sound that impressive since noone has seen any of GR working but I have scripting working at a minimal level in Galaxia Reborn.

I gave a ship the following script:

<script event="entersector">
<savetomemory name="w" value="($w+1)%4" />
<setcourse target="$waypoints.$w" />

$waypoints is simply an array of four coordinates. The function savetomemory just saves data to the ship which is read back in when the script next executes.

oop, programming, scripting]]>

Galaxia, PHP

Working user scripting

<![CDATA[The user scripting I mentioned before I went to Brussels is now basically done. The most amazing part is that I did most of it while I was in Brussels on a computer without PHP (amazing because apart from a few minor typos it actually worked).

The whole thing is actually simpler than I expected it to be and as such it can do stuff I didn't plan. The first is maths expressions. This is something that may cause a problem however since it just just evals the code (after substituting variables and stripping possible harmful stuff).

The coolest feature I think though is handling aggregate data types. When you call a script you also pass it an array of variables. These variables can be of any type from integers or strings to arrays or objects (or even resources); it’s upto the functions you define to actually handle them. Now different elements of arrays and properties of objects can be accessed using a slghtly suspect-looking dot notation. So (from a working example I wrote) you could use something like $ which would access the name of the second element of the fleets array.

It’s worth pointing out that I decided to stick with numbering arrays from 0 since as a programmer that’s what I’m used to.

Anyway when I say that is accesses the name of the second element, it checks the type of the element and accessed it as an array ($fleets[1]['name']) or a property ($fleets[1]->name) as appropriate.

You can also do $fleets.$ to access the name of the nth element (although be warned that if n doesn’t reference a key of the fleets array then it won’t work obviously). Which brings me to biggest problem with it at the moment… everything fails silently if something isn’t right.

The way the scripting is called is also more flexible than I originally planned. The first way is:

$xgs->parseXGS('event', 'fleetentersector', $script, $vars);

$script is the a well formed XML script and $vars is an associative array of variables. Any script tags with an attributes of event equal to fleetentersector (<script event="fleetentersector">). This is was done mainly with Galaxia in mind so players could create different types of scripts other than ones designed to respond to events (i.e. use it just to create a batch command system).

The second far more flexible way to use it is:

$xgs->parseXPath($xpath, $script, $vars);

Where $xpath is an XPath expression selecting the root node of the script. Just to point out the first example actually just calls that with XPath expression "script[@$type='$att']" ($type is the attribute name and $att its value).]]>

Galaxia, Games, MPOGs, PHP

User scripting in Galaxia Reborn

<![CDATA[Something I've wanted to put into Galaxia for a long time is user scripting. i.e. allowing users to attach scripts to objects that are triggered by certain events. Ultimately this could lead to interesting computer players (but that's a long way off).

Well I've been playing around with it a little and the easiest complex data to parse seems to be XML. So the scripting engine will be XML based. The following is how a script will (hopefully) look:

  <IsEnemy target="$fleet">
    <ExectureOrder order="attack" target="$fleet" />

Just in case you can’t tell what it does, when a fleet enters the same sector as your own it checks to see if is an enemy and if is, attacks it.

Firstly a bunch of variables the script can read are passed to it. After that all the processing works using callbacks. When each tag is encountered, it just calls some specified function with the attributes passed as arguments (probably as an associative array to easily handle a variable number). If it’s a conditional (like “IsEnemy”) the function must return true or false. If it’s an action (like “ExecuteOrder”) then it returns nothing. There is also another type – one that returns an arbitrary value (i.e. a function – but I’ve used the word function too much already).

I’ll put the code up once it’s tested a bit more.]]>