6
\$\begingroup\$

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
       dobattle;
    else
       returnToNest;
    endif;
endif;

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?

\$\endgroup\$
2
  • \$\begingroup\$ You're going to want to parse that language into JS. \$\endgroup\$ Commented May 9, 2011 at 19:17
  • 2
    \$\begingroup\$ What's the game going to be called? It'd be interesting to check out the game when it's finished. \$\endgroup\$
    – Kzqai
    Commented Jun 16, 2011 at 14:46

1 Answer 1

13
\$\begingroup\$

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
       dobattle;
    else
       returnToNest;
    endif;
endif

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!

\$\endgroup\$
6
  • 1
    \$\begingroup\$ +1 I dig the resemblance to Alice and Scratch, which are good examples to study for teaching kids to program. \$\endgroup\$ Commented May 9, 2011 at 19:18
  • \$\begingroup\$ 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? \$\endgroup\$ Commented May 9, 2011 at 19:25
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Ray Dey
    Commented May 9, 2011 at 19:57
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Ray Dey
    Commented May 9, 2011 at 20:00
  • \$\begingroup\$ You might also want to take a look at the Mindstorms' UI. There's an online demo here. \$\endgroup\$ Commented May 9, 2011 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .