Search Unity

MiniScript: lightweight scripting language for your game

Discussion in 'Works In Progress' started by JoeStrout, Dec 14, 2015.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    EDIT: MiniScript is now available in the asset store!

    (I'd posted about this in the General forum, but realized that this is probably a more appropriate place for it.)

    I have been working for the last couple of months on a lightweight scripting language called MiniScript. It can be described fairly completely in a single page of documentation, so it is very easy to pick up and learn. And because it is written entirely in C#, it is trivial to embed in a Unity app.

    MiniScript source code is compiled down to a bytecode, which is then run through an interpreter. You can tell this interpreter how many milliseconds to run before returning, and then have it pick up right where it left off in the next frame. The set of intrinsic functions even includes a "wait" command that lets a script pause for any number of seconds — all without causing a hiccup in the host game!

    Feature highlights:
    • clean syntax without a lot of unnecessary punctuation
    • robust list, string, and map handling
    • object-oriented
    • safe (completely sandboxed)
    Even though it's fully sandboxed, it's easy to integrate with your Unity objects. Unity code can simply reach into the context of any script, and get/set variables as you wish. Or, you can add new intrinsic functions, or entire classes, to the script environment.

    I've put up a web demo that lets you play around with the language yourself — either in a read-eval-print sort of mode, or by writing a little script and running it. In either case, you have access to a "ship" map with x, y, and rot properties, that controls the position and rotation of a sprite on the screen.


    I'm looking for feedback on the language design, as well as (of course) reports of any bugs you may find. In addition to the quick reference page, the demo page also includes a link to the regression test suite. That contains hundreds of lines of MiniScript code and the expected result, so that's a good source of example code too.

    I'd also love to hear any thoughts you have about how you could use a scripting language like this in your games (or other games you love).

    Please give it a try, and let me know what you think!

    Asset Store link
     
    Last edited: Sep 1, 2017
    eelstork, Flipbookee, one_one and 2 others like this.
  2. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,440
    Looks like great work Joe. I've often thought about making a little scripting language to handle events and such. Will be sure to check this out when I return to Unity dev next year.
     
    JoeStrout likes this.
  3. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    442
    Seems useful.

    But that "end for" statement... :eek::mad::(o_O

    Go the Python path and just infer it from the indent.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Thanks!

    Goodness gracious, no! :p I understand the pros and cons of it, and it was an interesting experiment that somebody needed to try... but now we've tried it and seen the grief it causes; we can do better than that!

    I would consider replacing end for with next if there were enough clamoring for that... but since we're already using end while and end if, I like the consistency of end for. No need to guess; the end token is always just end plus the opening token.
     
  5. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    442
    This prompted me to look for a poll. It seems we indent-based nesters are outnumbered by curly-bracers :( (about 2 to 1): http://forums.xkcd.com/viewtopic.php?f=11&t=38636

    Note that indent-based nesting is still the second-most preferred though; much more so than the "end"-style used in Lua, anyway. (I doubt the actual difference is that extreme, as it was a small poll, but the results are still worth considering)

    My favorite is actually for indent-based nesting to be the default, but for curly-braces to be allowed to used, if they are given.

    Best of both worlds. Indent-based nesting is fine most of the time--you just drop the braces; but single-liners (or weirdly-indented blocks) are still able to be written if desired, simply by having the next non-space char be a curly brace.
     
    Last edited: Dec 15, 2015
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    The problem with Lua's "end" closer is that it's too unspecific; you can't quickly tell what it's the end to (unless the user adds a comment, but that's just expecting the user to work around a flaw in the language design — which most users, being lazy, will not do anyway).

    This is not only a problem for the human reader of the code, but also for code editors (i.e. software for editing code), which can very easily get confused about what matches up with what as code is inserted or deleted. With proper (strongly matched) block closers, the editor can keep things matched up and indented even when things are in a half-edited state, and correctly show which block is still missing its closer (or which extra closer has no opener) most of the time. (The REALbasic code editor works this way — and it's way better than any other editor I've ever used in this regard.) It's also a problem for the parser, when it comes to reporting a sensible error message when things are mismatched. Messing up one closer (or opener), and suddenly matching ifs with end-whiles and fors with end-functions and so on, all the way down to the end of the method (or the file!), is just stupid — it's amazing we put up with it!

    Note that curly braces have exactly the same problem.

    This cascading-mismatch problem is one of the motivations behind indent-based blocking, but that brings a whole host of problems of its own. Using specific words (for/end for, while/end while, if/end if) is a simple, clear solution that solves all the problems, creates no new ones, and is easy to read. The only drawback is that it's a little more to type, but in the course of a program it's a very very minor increase.

    (Well, the other drawback is that, due to the current dominance of C-derived languages, it is nonstandard... but that is just a historical accident, and I can't bring myself to perpetuate a clearly worse solution just because it is common. And yes, I type in Dvorak!)
     
    Venryx likes this.
  7. Venryx

    Venryx

    Joined:
    Sep 25, 2012
    Posts:
    442
    That's a good point. I do think it becomes less of a problem as our compilers become "smarter", but I have seen cases where it still comes up. (I think for the major IDE's, for example C# in Visual Studio 2015, it's mostly a non-issue nowadays, because you instantly see the red underlining when you mess up a brace, and just correct it; but for basic text-editors like those possibly used in games for scripting, that could be a significant annoyance)

    From my coding in Python for a few projects, I didn't actually notice any major issues/annoyances with the indent system, but perhaps I just didn't go deep enough to run into them. (the main project was a model/animation exporter for blender)

    On this point I wholeheartedly agree. (Very cool that you type in Dvorak!)

    I really respect people thinking through an issue and sticking with what they see as the best long-term solution, even if it might not be ideal in terms of ease of transition/practical usage for some time. In this case I disagree with your conclusion, but I very much support the reasons you hold to it.

    As a side-topic, I feel a similar way about our world languages. There are many inefficiencies that we could remove if we just had our schools gradually shift the rules they teach, but instead the people writing English books tend to actually perpetuate bad rules just because it's a little more in-synch with how people currently talk and write (or how the last generation did anyway). Really disappointed that cirriculums haven't been taking up the job of introducing improvements to our language.
     
    JoeStrout likes this.
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Hey everyone, I've just posted Robo-Reindeer Rumble, a programming game built around MiniScript. Please check it out!
     
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,355
    The problem with having specific closings or even just word closings becomes obvious with closures or certain coding styles. It's why ruby supports both 'end' and braces. specific closing tags just make your code much more difficult to read with a sufficiently powerful language. For a very simple language I think it's ok.

    I'm curious what kind of parser are you using for this?
     
    JoeStrout likes this.
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    It's a recursive descent parser.
     
  11. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,355
    I've been toying with the idea of using something like this for controlling npc behavior in an open world building game I'm working on. I wanted something addicting that people could spend hours tweaking, and a way to make their part of the world unique.

    The issue I run into is that what I really want for players looks more like a DSL. I think a good DSL presents itself as something that even non programmers could use, because they can actually read it and have an idea of what it does at the very first glance, without any previous programming experience. Now it's still logic and they have a learning curve, but I'm thinking it would get a lot more people to actually try it.

    For example Cucumber lets you specify a lot of fairly complex logic using standard english. A lot of testing tools now take the approach of using easy to read words appended in dot notation that become phrases anyone could look at and have a good idea of what it's doing even if they are not developers.

    So if the problem is one of I want to give players more power and functionality they can spend hours in, then I don't know if just a simpler general purpose language solves that problem well. Because I think the biggest barrier is actually that it looks and feels like a programming language. Now if you are out to teach people to code that's a different story.

    And all of this kind of raises the question of whether any language is really the right approach, or do you just encapsulate the functionality you want to give in a UI. At the end of the day most likely there are just specific things players want to do, and those things can most likely be expressed in a UI. And that makes it even more accessible.
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yes, I think you're right. If you really want to encourage participation of non-programmers, and there's any way you can structure the problem so that you can fit a reasonable UI over it, you're best off doing that (even if it compiles down to code behind the scenes).

    For something like that, behavior trees are another possible way to go (which are really just a very constrained form of scripting).

    Then there's the in-between approach of having code, but wrapping it in little puzzle blocks you drag around and snap together, like Scratch, or pretty much any of the Hour of Code exercises. This is becoming such a common metaphor that many people will recognize it right away. It's a slow way to write code, but has the big advantage that syntax errors become pretty much impossible. (MiniScript could serve nicely as the backend layer for something like that.)
     
  13. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    I like this idea, I haven't thought about it much before, but it would be fun to put small programming type of puzzles in games and see how they manage with it.
    Actually I just remembered minecraft, it had simple logical elements, but with an "if-branch" block and an "integer-memory" block you could do a lot more with fewer block. Someone should make this xD (At least as a demo)

    I myself wanted to write a lightweight in-game scripting language, but mostly because I wanted to test behaviors in bigger projects on-the-go. Recompilation is such a bother...
    Also imagine if you could execute function calls from within the editor, that would be cool, actually I know how I would make this (just make the same editor gui window for selecting functions, as the one the Button components has), but I'm too lazy lol

    Btw is your mini script open source? I'd like to take a look if you don't mind.
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yeah, lots of open-world games have some sort of scripting... Second Life has LSL, etc.

    Yep, and not even possible on the user's machine. So, with a scripting language built into your game, you could distribute updates (fetched via the WWW class or whatever) that actually change the behavior of the game.

    It's not open-source, exactly, because I plan to sell it via the Asset Store. It won't be too pricey, but I can certainly spend more work time on it if it's bringing in at least a little revenue! However source will be included with the package, and it will probably end up open-source eventually.

    It seems to be quite solid now, but I still have a fair bit of code clean-up before I'd be ready to distribute it widely. But PM me if you want to have a sneak peek.

    Meanwhile, be sure to try Robo Reindeer Rumble... somebody needs to knock my "Charger" script off the throne!
     
  15. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    My general idea was to make a launcher program that checks for updates before starting, since that would also update other assets.
    But your solution would be faster, since you could make a WWW request and get the new logic while the user is i the menu.
    It would even work in mobile games.

    And I was just interested if you're using System.Linq.Expressions or something else?
     
  16. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yep!
    Something else. It's a completely custom parser, bytecode compiler, and runtime engine. See the MiniScript Quick Reference for an overview of the language.
     
  17. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    A small update: I've added a new shuffle intrinsic, as a method on lists and maps, which randomly permutes the values. (In the case of a map, this means that the mapping from keys to values is randomized). For example, you could try:

    Code (MiniScript):
    1. x = range(1,10)
    2. x.shuffle
    3. print(x)
    Also, under the hood, I did a small but important optimization in assignment statements, eliminating a temporary variable and making them one step shorter. Since typical code has a lot of assignment statements, this is a good win. I plan to do a few more optimizations before the official release.

    The demo and game have been updated, as has the quick ref document.
     
  18. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    One of my pre-release testers has gotten a MiniScript REPL (read/eval/print loop) working in a Hololens project:



    Very cool!
     
    Flipbookee and zyzyx like this.
  19. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    Interesting, looks like the language can have nice real-life usages.

    REPL systems go well with simple scripting languages, although I'm having much more fun with using C# REPL in the editor, since it's so easy to interact with the rest of the code and you get to use all the language features.
    Have you tried using Mono's C# evaluator?
     
  20. RealMTG

    RealMTG

    Joined:
    Jul 27, 2013
    Posts:
    229
    I've been wanting to make my own simple scripting language for quite some time but I have no idea how I would go about to make sure the formatting is correct and read values. Since you've got a start here, I assume you know a bit on how to actually do that. So do you have any resources I could use to try and make something like that?
     
  21. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yes. It's a bit tricky if you haven't done this sort of thing before. But here's a decent starting point.
     
  22. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Hey all,

    I'm (finally!) polishing this off and getting it ready to submit to the Asset Store. This is mainly a matter of writing documentation — I've had some alpha testers working with it for a while now, and what few issues they found have been fixed.

    The existing MiniScript-QuickRef document will ship pretty much as-is; I've only tweaked the formatting a bit. In addition, I'm planning to add these much longer documents:

    1. MiniScript Reference: a detailed reference for the MiniScript language and standard intrinsics, which you can deliver to your users. (You'll want to also include a supplement documenting any new intrinsics or variables that hook into your game.)
    2. Integration Guide: a document for you guys, the Unity developers who are integrating MiniScript into your games.

    So, this is just an update to let everybody know it's coming, and to say: if you have any last-minute comments, questions, or feature requests, now is a great time to speak up!
     
    Dave-Carlile, zyzyx and one_one like this.
  23. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    I've finished writing the MiniScript language manual. (Man, that sort of stuff is time-consuming!) Check it out here:

    MiniScript Manual



    I just finished this, and confess that I haven't even proof-read it yet... so if you spot any thing suspicious or unclear, please don't hesitate to point it out!
     
    Starpaq2 and chelnok like this.
  24. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    Hi,

    just looking for adding scripting support to one app, would miniscript allow
    accessing unity components/gameobjects? (like moving objects, settings UI texts..)
    either directly or by giving your own helper methods to do that?

    currently testing moonsharp(lua) but its bit overly complicated, if just want to do simple things..
     
  25. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Directly, no; by adding your own helper methods, yes.

    Each MiniScript instance runs entirely within a sandbox, there is no direct access to objects in the Unity space. But you can add your own functions and classes that bridge this gap in exactly the ways you define. This is how the MiniScript demo lets you write code that moves the little spaceship sprite around, or how in the Robo-Reindeer game, MiniScript code controls the movement of the reindeer (but only in ways permitted by the rules of the game).

    So it sounds like what you want to do is exactly what MiniScript was designed for.
     
  26. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    Sounds good, that spaceship demo looks pretty much suitable already..
    (what kind of backend you have there on c# side? how self. passes the values to transform position)

    Also, would this work on webgl and ios? (i guess you are not using any c# reflection stuff..)

    And roughly when this one is going to asset store?
     
  27. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    That one uses a very simple interface... the C# code can look up (and modify) values in the MiniScript global variable space. So we just define a global "ship" map containing x, y, and rot (rotation) values. The C# script, in Update, just looks this up and sets the position and rotation of the sprite accordingly.

    Yep, works fine.

    It won't be long now! I just need to write that integration guide.

    (But if you really can't wait, PM me and I'll sneak you a pre-release version.)
     
  28. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    thanks! ill message in a week or 2 after get started on that..

    Can you call a miniscript function from c#?
    say i want to do this
    - miniscript: Create sphere gameobject (using helper class/method to create unity objects)
    - then in unity c#: I click that sphere and call miniscript function like, ObjectClicked(objectName)
     
  29. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yes, that would be doable.

    Thinking about this a bit, I guess I would instruct my script writers to write those various event handler functions (ObjectClicked, etc.), in a script with little or no global code. And then I would append to their script a bit of event-loop code, which calls custom intrinsic functions to check whether the object was clicked, collided with something, etc., and then call the appropriate methods.

    So then you'd run this script, and it would sit in a loop, just checking for events each frame. And your C# MonoBehaviour would simply set the appropriate flags (clicked, collided with something, etc.) and report these to the script through those intrinsics.
     
  30. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    I've just (finally!) submitted MiniScript to the Asset Store!

    Hopefully Unity won't take forever to get around to reviewing it... I'll keep you posted!
     
    Flipbookee and FlyingRobot like this.
  31. FlyingRobot

    FlyingRobot

    Joined:
    May 5, 2012
    Posts:
    451
    Looking forward to it.
     
  32. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Well, nuts. There was a problem with my submission — the demo scene (the same one you see here) uses layers to keep a background canvas behind everything else, including the sprites. But when it's imported via a package to a fresh project, that project doesn't have the right sorting layers defined, and so the background ends up on top of everything.

    So now I have to find another way to arrange this scene that doesn't depend on project settings, and submit a fresh package to the store. I'll keep you posted!
     
  33. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    OK, new package is submitted!

    I'm so excited about this... I think people are going to really like it. Fingers crossed for a speedy approval!
     
    Dave-Carlile and zyzyx like this.
  34. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    I am delighted to report that


    MiniScript is a high-performance, easy-to-learn scripting language for your game or simulation.

    Written entirely in C#, and with Unity integration in mind, MiniScript is the best way to let your users (or your own development team!) script behaviors in your game. Applications include:

    • Add mod support, enabling users to add custom behaviors, AI, or other features, without breaking your game!
    • Create a programming game, where players write scripts to control tanks/robots/etc. in the heat of battle!
    • Give your designers the ability to easily script cut scenes, AI behaviors, and more, even in already-compiled builds of your game!

    MiniScript is compatible with all platforms, and runs in a carefully constructed sandbox — MiniScript code has access to exactly those Unity values and functions you provide.

    Includes a 1-page quick reference and MiniScript manual which you can deliver to your users, as well as a detailed guide to integrating Miniscript into your own game.

    Handy links:

    I am committed to making you successful with MiniScript. If you have any trouble, you'll get quick and thorough support from me.

    Download MiniScript now, and start making your game scriptable today!
     
    Dave-Carlile and FlyingRobot like this.
  35. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    Nice!

    One question,
    Would it be possible to implement sleep() command with this? (meaning, script execution would pause for x seconds)

    *ok looks like there is wait() already, that probably works.
     
  36. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yep, that's exactly what wait does. "wait" by itself pauses 1 second, or specify how long to sleep, like "wait(2.5)".

    (As a matter of MiniScript style, when calling a function with no parameters, don't use empty parentheses.)
     
  37. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,453
    That's why I don't like python. I think it's probably best to stick with basic style. Didn't hurt blitz all these years :)

    Miniscript seems interesting to me for all those things that require decision making by level designers or even dialogue trees etc... cool.
     
    JoeStrout likes this.
  38. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yeah, particularly if you deliver content (new levels, mini-games, etc.) as asset bundles... those can't contain new C#/UnityScript code, but they could contain new MiniScript code.

    In that sense, it allows you to blur the line between "data" and "code"... which could be pretty useful if you draw the line carefully.
     
  39. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,453
    Well, it does allow modding in a big way and should be marketed at modders as well... :)
     
    Dave-Carlile and JoeStrout like this.
  40. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    Possible to have webgl demo build? (that current one is on webplayer)
     
  41. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Yeah... it's on webplayer because, at the time anyway, WebGL had serious bugs in multi-line InputFields (quite unrelated to MiniScript) that made it very unpleasant to use.

    Other than that, it worked fine, i.e. MiniScript itself works fine on WebGL. I'll give it another try when I upgrade to 5.6 (which should happen soon) and see if WebGL's UI has gotten any better.
     
  42. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    Nevermind, purchased and got quick demo to show running in ~5 minutes. Looks good so far.

    Used https://ace.c9.io/ code editor in the webpage, and then run script in webgl player.
    upload_2017-5-15_11-7-44.png

    ps. integration guide page 5 maybe missing }; from that example snippet
     
    JoeStrout and zyzyx like this.
  43. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    That's awesome! :D I hadn't seen that code editor before. What a cool combo! Can you share more about how you did it?
     
  44. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    its just a web js calling the webgl player with SendMessage(myscript-string) and that gets run,
    could do all kind of things with that.

    Having miniscript syntax highlight for this editor could be easy, if had a list of your keywords:
    https://ace.c9.io/tool/mode_creator.html
     
    JoeStrout likes this.
  45. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    That's really neat.

    All the keywords are defined in MiniscriptKeywords.cs. Here's the list:
    • break
    • continue
    • else
    • end
    • for
    • function
    • if
    • in
    • new
    • null
    • then
    • repeat
    • return
    • while
    • and
    • or
    • not
     
  46. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,344
    JoeStrout likes this.
  47. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    That is rocktastic with an extra helping of awesome sauce. Great work!

    I've thought about putting up a MiniScript playground, where you could play around with code and sprites and such, store your code in the cloud, and even make little games and such you could share with others. But making a decent code editor was the biggest hurdle. Possibly with this approach, that hurdle is solved!
     
  48. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    Hey, BTW, everybody who's given MiniScript a try — could you take a minute to write a review on the Asset Store page? It's only gotten one review so far (though 5 stars — thank you, Etabubu!), which is not enough to display an overall rating.

    Positive reviews really help people know they're not buying junk. So, your help with that is appreciated.

    Thanks,
    - Joe
     
  49. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    20
    Hi! This looks great!
    Have a few questions, because I am not versioned in moding scripts, (but will be:)) so I am little confused.
    On example, if I want to get in code which is presented at the top like an example, there is mentioning of 'ship.reset'.
    Ok, so 'ship' represent ship from game, and it is inside of the context of the MiniScript.
    How it is achieved? I mean how you 'setup' variable 'ship' and get it in MiniScript code?
    And second question is:
    Can I get any object from current scene in runtime, based on name of the gameObject and use it imediately?
    Something like GameObject.Find(object_name) function in Unity?
    ... and off course, to change values from some components which are attached to object?
     
    JoeStrout likes this.
  50. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,126
    'ship' is a global variable referring to a map in MiniScript, which in your C# code, you get via interpreter.GetGlobalValue (which would return a ValMap in this case). The code looks like this:

    Code (CSharp):
    1.     public void UpdateFromScript() {
    2.         ValMap data = null;
    3.         try {
    4.             data = interpreter.GetGlobalValue(globalVarName) as ValMap;
    5.         } catch (UndefinedIdentifierException) {
    6.             Debug.LogWarning(globalVarName + " not found in global context.");
    7.         }
    8.         if (data == null) return;
    9.        
    10.         Transform t = transform;
    11.         Vector3 pos = t.localPosition;
    12.        
    13.         Value xval = data["x"];
    14.         if (xval != null) pos.x = xval.FloatValue();
    15.         Value yval = data["y"];
    16.         if (yval != null) pos.y = yval.FloatValue();
    17.         t.localPosition = pos;
    18.        
    19.         Value rotVal = data["rot"];
    20.         if (rotVal != null) t.localRotation = Quaternion.Euler(0, 0, (float)rotVal.FloatValue());
    21.     }
    (This is part of GameObjScript.cs, one of the demo scripts included with the asset.)

    No, that would expose your game to all manner of hacking. MiniScript code can only access C# objects and properties that you specifically provide access to, via custom intrinsics or some specially-named variables that your C# code looks up (as above).

    If you like, read through the MiniScript Integration Guide, which has more details about how to integrate MiniScript into your Unity game. And if you still have questions, feel free to post again! I'm traveling to Japan this weekend, so I may be a little slower than usual to respond, but I'll get back to you as quickly as I can.