How to make programmable environment at game?

So lets say I want to make the structure that in my game, gamer can do basic programming, setting variables even though gamer can’t set fully about variable’s name, but user can set any value (int, float, etc) to variables I made.

And user can use basic syntax like (if~else, goto likely effect, for, wait for second effect, if conditions (something in game happens)).

And this should be done only by touch or mouse, keyboard should not be used at all.

How can I make this programmable environment by unity?

There are some decent LUA plugins available.

How exactly do you want this done by touch?

Do you want a virtual keyboard, or do you want to create some kind of drag-and-drop interface for programming “blocks” (like Snap!)?

Do you have an existing programming language in mind, or do you want to create your own?

What is the goal of your game? Is it a teaching thing, or a puzzle thing?

^ I immediately thought of something like Snap/Scratch (or plyBlox), too.

You could use touch-and-drag in Unity UI to drag blocks from a library of block types and snap them together in a workspace.

Edit: Apple also recently announced the upcoming Swift Playgrounds, which might be helpful to glean ideas from.

Perhaps nice node based interface can be applied it is quite easy to make and if done properly easily extensible.

I’m also working on a scripting environment called MiniScript, which is written in C# and easy to embed in a Unity app. You can try it here or via here.

I’m actively seeking beta testers while I polish off the feature set and work on the documentation. So, if you’re willing to work with it while it’s still a bit raw, PM me and I’ll be happy to get you started.

No virtual keyboard, but just simple drag-and-drop interface, yes like you said.

Hm…I don’t have any specific programming language at all in mind because this sort of thing should be easy for users, so want to include very basic universal programming ‘blocks’ like (if~else), (for or loop), (wait or turn structure), (basic variables set usage), (can execute something),

Goal of my game, but not teaching game, but just it can be puzzle or traditional RPG likely game.

Seems interesting and want to know how to make that, but scripting way is not for most users because it become too hard and professional to them. So I want building blocks type.

If you base it on Snap, you’ll have a head start because they’ve already worked out the blocks you’ll need. And it’ll also be more familiar to people who have used Snap – or, vice versa, people who play your game will get a chance to learn Snap while they’re playing.

Yeah, but how would you get this into your Unity game? It sounds like @leegod 's looking for something off-the-shelf that already does this, but I’m not aware of any such thing for Unity.

I started such a project myself a couple years ago, when I was trapped in Australia and didn’t want to leave the house for fear of being stung, bitten, or mauled by drop-bears. But it’s based on the (now) old GUI system, and would need to be rewritten using the modern UI. And it wasn’t finished anyway… managing all those drag-and-drop blocks is a fair amount of work.

@leegod , if you do end up writing your own blocks UI, you’ll still need a script engine under the hood to actually execute the code. MiniScript might be good for that. You could also translate to something like Lua if that’s more your cup of tea. Or you can write your own, though that’s a lot of work in itself. (Though the blocks do save you some of the effort of parsing.)

Sorry, I meant just base the structure on Snap. But, yes, you’d have to implement it all from “scratch” :wink: in Unity. Unless @JoeStrout decides to write a block programming UI for MiniScript, which would be cool. It might make an interesting niche product on the Asset Store.

I’ve considered it. I’m a little worried it might be a bit too niche. But maybe not.

In any case, I need to polish up and post MiniScript first, and then see about layering a blocks UI on top of it.

Are there any opened source to implement like that? (Snap)

So I need to do that [under the hood] part, but also I don’t have much time recently… Miniscript? where is it? Listed at store? or github? Anyway, whether free or not, I need reference to actually implement this system, prefer that already done.

Scratch is open source. I believe it’s written in ActionScript, so it shouldn’t be difficult to translate to UnityScript if that’s the route you want to take. I was thinking more about taking the Scratch language definition and general interface principles, but writing the code for Unity from the ground up.

It’s not released yet; the feature set and API are fairly complete, but may need a little more polish, and the developer documentation still needs to be written. It’s discussed here (and here), and demoed here and here.

However, I could use more beta testers, so I’m handing it out to pretty much anybody who asks for it and offers to provide feedback. If that’s you, PM me!

OK, I did some research accross for this, and yes, LUA is nice, probably already in place, probably much easier than working from scratch… However, for those of you who want to play with this…

There is an article here:
http://www.codeproject.com/Articles/345888/How-to-write-a-simple-interpreter-in-JavaScript

This article describes how to make a “parser” which will parse text and make it tokenized objects that can be evaluated. Its all written in javascript so you can run it anywhere.

What I did was to take all of this code and compiled it so that you can see the javascript in packets (lex, parse, evaluate and calculate and posted it up on my website. It is available here. Just look at the source, and the javascript file it points towards.

http://lod3d.net/Script/

What this means… You can make your own parser, make your own scripting language and not have to rely on buying anything… And if you do it good enough… Make money off of it through the asset store. (always in favor of money)

this let you execute code during runtime. if you want to hide it behind a clickable interface you will have to construct the code from your interface but i guess this is not trivial. mostly because code is not flat but hierarchical. you must answer questions like:
how does the user navigate through existing code (for inserting, removing, changing).
how is an existing variable renamed?
how do you check the code for errors?
how are different instances handled?

In general your own internal code should provide a small set of exposed functionality for the user to utilize. you should be aware UPFRONT what this functionality consist of and how does it interact wirth your internals.