One Game Per Day – Day8

Today’s game has been inspired by a r/gameideas/ thread on reddit by /u/TheJonesy. I figured I could give him credit in the game’s name so hear is the first day of work on Jonesy IDE.

Game 8 – Jonesy IDE (Day1)

Write code to interact with the game and solve puzzle.

Write code to interact with the game and solve puzzle.

Play Jonesy IDE!! – WebPlayer

Idea :

The idea is a mix-up of the ideas found on the Reddit thread. The objective would be to have puzzle that are solved by entering command in the command line. I would like to make the command line really feel and designed like a language. Eventually, a full editor could be added to allow more control to the player. There’s a lot of work to do before then.

You can use the Help() function to have a list of all currently implemented functions. The commands that would be implemented are things like Create(Door,”Door1″, [2,2])  then Door1.Open. Another idea would be SetTrigger(Button1, Door1) then, you could press the Button1 to automatically open the door1.

If the code design get powerful enough to create an editor, the levels could be generated by the in-game code and allow player to edit the generation of a level to solve a puzzle or create custom maps for fun.

In simple, I want to create an interface language, Rod#, that will allow control of the Unity API at runtime.

Design :


The principal scripts of my project are the following :

–  GameManger.cs : Responsible for the initialization and managing of the overall game. Not deleted on scene loading.
–  LevelManager.cs : Responsible for the initialize and managing of a level.
Compiler.cs : Evaluate the syntax of the code and evaluate the type of command to be executed
Linker.cs : Execute the commands(functions for now)  called by the compiler
– Function.cs : Class for each function. Contains its name, definition, inputs, input types…
– FunctionType.cs : This is where I create and store the List of function. The values should be imported from outside the game eventually(JSON or XML)
– Controller2D.cs : Control and animate the 2D player.

To make it short :

When a Function is entered, the Compiler look at the syntax and evaluate the type of command to execute. The Linker execute said command.

Command Window

I started design my own command window at first but realized the NGUI example close to what I wanted so I imported it and modified it to my taste. I added a button that call the same Callback as pressing Enter on the Command line input. This Callback give the command to the compiler that then verify and execute the line of code if its valid.

Call a function from its name in a string

This took me a while to get working. For each Function that are defined in FunctionType, a C# function is defined with the same name in the static class Linker. The function name is feeded to the linker that then execute it.

The first answer of this SO question got me started but didn’t touch the specific of a static function in a static class. The answer on this second SO question put me on the right tracks with the BindingFlags. A look at the MSDN documentation for MethodBase.Invoke answered the rest of the problems.

Here is how I do it for the _functionName function with no argument that is called from the static class Linker:

 using System.Reflection; // For MethodInfo and BindingFlags

 object[] _arguments = new object[] {};
 MethodInfo theMethod = typeof(Linker).GetMethod(_functionName);
 theMethod.Invoke(null, BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public, null,null, null);

Next day of work:

There is so much to do in this game :

  • Allow function to take inputs
  • Create an object system that will allow player to access property of some objects (i.e : Box1.Collider = false; Player.Controller = true)
  • Create an interface to see documentation and allowed function call
  • I’m interesting in prototyping early some kind of IntelliJ system to have real-time code completion offered to the player
  • Add more level that would be solved by code

Conclusion :

This is no simple task, the objective is to design a language that works on top of Unity/C#. It will be interesting to see the console accept more function as time goes by. This project will require me to learn a lot of design language theory which is good for my overall low-level programming knowledge.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s