Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Building a coding game

Discussion in 'General Discussion' started by Fceek, Oct 19, 2021.

  1. Fceek

    Fceek

    Joined:
    Dec 16, 2019
    Posts:
    8
    I was just over intrested in making these base building and factory games. Recently I came up with a even furthur idea that players write code in the game that completes all kind of operations, which leads to extreme automation XD

    After some researching I find it not easy to get valueable resources about this topic (maybe too few people's trying to make a coding game with unity) and I don't know how the project should start. So I'm sincerely here to ask for something like:
    - Do I need to embed a full language environment into unity;
    - To what extent my language choice would impact, like, maybe scripting languages are easier for this purpose? What if I insist to use some programming language(C#? write C# to play a C# writen game LOL);
    - Anything I'm not awaring of but might help (or make me suffer).

    Thank you
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,588
  3. Fceek

    Fceek

    Joined:
    Dec 16, 2019
    Posts:
    8
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,588
    I've just moved it for you.
     
    Fceek likes this.
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,624
    It is a reasonable enough idea, yes. You can roll your own, but this will take time.

    This actually has a massive impact, because some languages are not really made to be embeddable.

    SpaceEngineers use C# for scripting, and the resulting experience is quite awful, for couple of reasons.

    C# wants everything encoded into a class and SpaceEnigneers hide the class enclosure. So, you type things and then before compilation it adds a hidden "class UserProgram{ }" enclosure around it. This means you can't use modules.

    C# as a language needs syntax highlighting and code autocompletion, as it is incredibly verbose. Their built-in code editor has none and does not support tab. Meaning to make a script you have to download external IDE, and then it feels like work.

    Additionally, there are security issues. C# can access entirety of user's system. So you'll need to take care of that by disabling some features.
    ----
    A decent choice for an embedded language would be lua, maybe python or maybe common lisp. (Aside from bizzare lisp syntax), all those language allow programming in procedural style, without classes, which is what you want to give to a beginner programmer.

    Another option is giving people a "block" language similar to Scratch. An example of that is Autonauts.
    You'll have to implement something like that from scratch yourself.

    One more option is giving user a discrete logic chip visual programming. This has been done in Main Assembly, Factorio and in Turing Complete.

    upload_2021-10-19_16-49-12.png

    Few things you need to keep in mind. If you go with digital circuit route, you definitely need to give your users an ability to save "blueprints" and design "components". It also makes sense to implement a "function" node, as some things are hard to implement via digital circuitry. Additionally, this sort of programming can quickly become resource intensive (depending on what you're doing), and normally belongs to signal processing. Meaning there may be no "state", only input and output.

    And then there's one more approach, which is mechanical circuitry/analog computer. That means you implement buttons, sensors and pistons, which are driven by physics engine and then you chain them together. So, for example, when a button is pressed a piston extends, block a sensor, which makes the door open. In other words "Rube Goldberg machine" This can also be resource intensive. This approach was used in scrap mechanic, and I think "From the Depth".
     
    angrypenguin likes this.
  6. For this purpose, I would not embed a full programming language. To be honest, I would write my own very basic assembly language (assembly line, assembly language, get it? :D) and make it highly specialized and very restrictive.
    You're only operating some very basic building blocks after all.
     
    Joe-Censored likes this.
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,624
    Been there, done that, except asm doesn't seem to be a lot of fun in practice.

    There's Automachef on the market, which uses this for programming some things, at least some reviewers weren't very happy with that.
     
  8. It is for me. (This is why I have to test all my ideas with real people, I have a weird taste...) :D

    ---
    Forgot to add, if you don't do assembly, you can check out @JoeStrout's MiniScript.
    https://github.com/JoeStrout/miniscript
     
    Last edited by a moderator: Oct 19, 2021
  9. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    524
    You can add moonsharp really easily, and have a lua programming environment up and running without too much fuss. You then decide what kind of API you'd like to expose to the lua scripts. They can be stored as plain text files, editable by external programs, or you could add some basic code editor into unity. There are assets that do that on the store, but I haven't used them.
     
    Antypodish likes this.
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I agree. I wouldn't use any full blown language. Having to learn a full programming language to play a game just doesn't sound like fun for players. You'll get players who already know it, and everyone else skips the game.

    For this reason I wouldn't use Lua either. As far as programming languages are concerned, it is pretty obscure. So you'd seriously limit your potential player base.

    I'd probably go with writing my own very simple interpreter, with syntax similar to BASIC. No support for separate functions, classes, etc. Maybe support goto for repeatable code.
     
  11. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    2,000
    An old PlayStation game "Carnage Heart" had visual custom programming. It was about small groups of computer-controlled robots fighting. A robot's program was on a 2D grid with each square being one command that moved to an adjacent square. You got an adaptable sensor command like "if [enemy] is in [this arc] from me within [30] meters...". True moved to one adjacent square you choose, False to another (The wikipedia page has a picture). Of course you also got Fire, Duck, Jump, walk, and turn. Control started from the upper-left, followed your graph until it dead-ended or did something, then restarted (but you could place do-nothing commands that just went to another square to make loops, as in actual loops). Part of the fun was chaining them to get things like "if an enemy is within 80 yards and no friend is directly in front of me within 40 yards".

    If was easy enough to make a so-so program (and the game would make one of those for you), but you could do better than that with practice. It's a bit like programming Scratch today. Plus got got types of robots and better designs, so could focus on the hardware more if that was your thing.