Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a simple strategy game, the goal of the game to teach programming basics to kids.

The concept of the game is simple, there will be a set of colony individuals - different type (resource gathering, fight, defend, scout ..etc).

I want to build a Campaign mode for this game, simple set of scenarios and missions as beta version.

As I said, the purpose is to teach programming basics, so player need to code there strategy to play the game, means that each colony individual's behavior will be programmed separately.

I am thinking of creating a basic syntax for code conditions, commands and actions (custom language), player will simply code individual's behavior by simply grouping these conditions, commands and actions in logical order. An example:

if FindEnemy
    if stamina > 0.6

My question is that I am building the game using HTML5/CSS3/JS, and wondering I can implement it a client-side library to parse custom language and convert it to animation? or whether there is already built JS library or engine that can do similar requirement?

share|improve this question
You're going to want to parse that language into JS. – The Communist Duck May 9 '11 at 19:17
What's the game going to be called? It'd be interesting to check out the game when it's finished. – Kzqai Jun 16 '11 at 14:46
up vote 13 down vote accepted

If this is for kids, then another option is to use a GUI based alternative. Taking your example as reference:

if FindEnemy
    if stamina > 0.6

Rather than getting them to type out text, you can have blocks (very literally) like so:

enter image description here

Then you can work out what kind of mechanism you could have to insert an available block into the into the behaviour blocks. This essentially makes up a sort of script, where the users can drag over an IF block and enter a condition.

This method offers a number of advantages:

  • Much easier to implement than text parsing as you don't need to worry about syntax errors (which is probably more likely to happen with first-time programmers).
  • You can easily limit the scope of your work as the amount of functionality you give to the user is dependent on what blocks you make available.
  • It's a much nicer experience for the user if they're starting out. Since they're scripting a game, they want to be able to see the results of their efforts as soon as possible, there's no need to memorise any APIs as all the available functionality is laid out in front of them and it's their choice.
  • You can also help their debugging woes before they even compile and run by checking there aren't any illegal block combinations as soon as you can (for example, an ENDIF block when there's no opening IF)
  • You more or less know what to expect from user input. For example a user typing in "IF BLAH YES THIS SOMETHING!! WOOP1!!1!" would probably result in invalid syntax, but let's say an IF block had a combo box in it to select all possible attributes that have conditions (like stamina) then you know the input they provide is legal.

I understand that this doesn't completely answer your question regarding text parsing, but I thought I'd suggest another method of doing so that might be a lot easier than a lot of syntax headaches for both the end user and yourself.

Hope that helps!

share|improve this answer
+1 I dig the resemblance to Alice and Scratch, which are good examples to study for teaching kids to program. – michael.bartnett May 9 '11 at 19:18
Actually, this is better than what I am thinking of! And I will try it for sure! Brilliant! Couple of questions: - Do you think it is a good idea to let players change colony individual's behaviors while the game is running or make the coding only available before running the simulation (for example, like light-bot game)? If you think it would be nice idea to give the option to change behavior while the game is running, then is it technically possible to process code changes while game is running? Or it is intensive task? – Ahmad Alkhawaja May 9 '11 at 19:25
It really depends on the design of your game. If it's a deterministic scenario, then after a change to a script you could just restart the scenario and see the effects. It would probably be easiest from a development perspective to "compile" before running the scenarios and see how it pans out until the end though. – Ray Dey May 9 '11 at 19:57
Otherwise, you could get your engine to fire a ScriptChanged event or something similar to let the appropriate characters know that their behaviours have been changed and they'd "recompile" it during game time BUT you would need to make sure if it's already in the middle of a behaviour being executed and that behaviour was changed, you want to either interrupt the behaviour, or let the behaviour complete and then replace it with the updated version. – Ray Dey May 9 '11 at 20:00
Thank you so much for your help! – Ahmad Alkhawaja May 9 '11 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.