Download

Programming game

I would like to create a programming/electronics game in which the player has to create a system to control something. My issue with this is creating a way for the user to program in game, so say open a terminal or whatever and enter in code.

What I would like to do is import a programming language (maybe in a self contained object that can read how many and what inputs and outputs it has etc) in order to be used to program something in game. Say for example the player is given a reactor with sensor outputs and inputs and are told to give parts of it commands depending on different conditions.

Does anyone know if this would be possible? I want to base it on real languages rather than create one just for the game, for example c++, python or maybe multiple different languages so that the player can chose what they are comfortable with or want to learn.

I know I could essentially create the language from scratch in a sudo sort of way but I think that could lead down a very dark path full of bugs and tears haha. (I also want the user to be able to design the control circuity for each part but that’s the next step).

I know there won’t be a simple answer for this but I does anyone know if it is possible? I have seen it in minecraft mods such as computercraft (they use lua) but I would really like to create something with cool graphics).

Seems I am doing something insane here then… would it be possible for example to take a string like for (i < 10; i++) do {set block color: “red”}; split it up and use construction script to do something? Shenzhen io is doing something similar to this (I know not UE4). The only thing I would really like to skip is trying to come up with a whole syntax and language to work in game. I would rather just take one that already exists and import it.

You can look at threads related to Unreal.js to get some ideas maybe.
But I think I’d rather chew off an arm or a leg than make this in UE4.

You can also rob gameplay ideas from games like Event[0] (Unity 3D).
While its not about coding, it does utilize typing gameplay + puzzles.

It’s not going to be easy unless you have some experience with integrating parsers, interpreters etcetera. Another obvious candidate aside from Lua, which you already mentioned, would be Python. Apparently fairly simple, relatively speaking, to integrate with a C/C++ host application.

An entirely different route, one that I’ve thought about from time to time, is to go seriously low level instead. If you want to expose a programmable interface to some in-game system, imagine instead a “virtual CPU” with a very, very limited instruction set. Programming would be done using something like an absolutely microscopic subset of x86 assembly language, which would be fairly easy to parse and every valid instruction would map cleanly to one specific native function operating on a small amount of “simulated RAM”. All of this, of course, having very little to do with UE.

Your second idea is my backup plan really, python might be the ticket I think. I have no doubt this project is going to make me rip my hair out haha

I have been thinking about what you said about the virtual cpu, I think it may be the way to go for some of this as people will be placing and programming micro controllers. I might use python and assembly (or just a very basic set of commands) together. Python for more complicated things and assembly for just the microcontrollers. So you have a main system, outputs to the circuit board, which then has to complete a tasking using its own inputs (3-5v, sensor input etc).

I actually depends how close to real languages you want to be. It might be much easier to use expression evaluator for some language (like Ruby or Groovy for example) and implement DSL & basic interpreter in it in order to use in you application.
Another way indeed is to implement something like JVM.

Of course everything is up to your skills.

For some things I want it close to a real language, for other things I will go with very basic low level commands. We will see what works best overall. I have decided to go with python, it seems there is already a plugin that might be useful in getting this done.