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,134
    A progress report...

    I've finished adding and fixing things for the next release, which I'm calling 1.4. I've been using it for some big projects of my own (like this one), and I'm very pleased with how it has shaped up.

    The next step is to revise the documentation — there are enough new features that this will be a bit of work, but hopefully done today. Then I will prepare and submit a new Asset Store package, including both the updated MiniScript core and the new in-game code editor. I'll be reducing the price to $30 at the same time.

    That's because as soon as I have submitted that package, my next task is to publish the source for the core — in both C# and C++ versions — on GitHub, along with some of the accessory implementations (like the Unix command-line version). And also continue to refine and improve http://miniscript.org, the main site for all this.

    So that's the plan! Asset update submitted probably by Friday; open-sourcing probably by Monday. And then I'll continue to work on my own apps that use/showcase the language, such as the command-line version and Mini Micro, and of course helping all of you integrate into your own Unity (and now Unreal too!) games.

    EDIT: User manual updated. So many parentheses slain... oh, the humanity! :p
     
    Last edited: Jun 5, 2019
    zyzyx likes this.
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    Version 1.4 has been submitted! Fingers crossed for quick approval. :)
     
    ratking likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    Version 1.4 is now live! In addition to the brand-new in-game code editor, here are the changes to MiniScript itself:

    - Fixed parsing of expressions where a function returns a map, and then you immediately use the dot operator, when invoking the function without parentheses.

    - Fixed an exception that could occur in the range() intrinsic if given non-numeric arguments.

    - Greatly improved the performance of string replication (string * number) for large repeat values.

    - Added limits to how big a string or list can get in some situations (such as concatenation and replication) that easily spiraled out of control before. To adjust these limits, assign to static properties ValString.maxSize (in characters) and ValList.maxSize (in elements).

    - Fixed a thread safety issue that could cause spurious "undefined identifier" errors when running multiple MiniScripts in different threads.

    - Fixed a bug causing functions with no explicit 'return' statement to sometimes return a spurious value rather than null.

    - Fixed a System.ArgumentException that could occur when using the same key twice in a dictionary literal, or when calling d.push(x) where x is already among the keys of d.

    - Fixed a System.NullReferenceException thrown when trying to print a list containing null.

    - No longer throw a "expression required" compiler error when trying to use null in a list or map literal. (Note: you still can't use null as a map key, but it's a perfectly cromulent value.)

    - Multiplying a list by a negative number no longer throws a System.ArgumentOutOfRangeException (instead, it just returns an empty list).

    - Fixed another ArgumentOutOfRangeException that could occur when trying to take a slice of a string with a negative total length (now returns empty string).

    - Fixed a "Stack empty" exception that could occur when an undefined identifier is used as an argument to a function.

    - Fixed a bug causing map equality tests to fail in some cases where the two maps included recursive references to other maps.

    - Parentheses are no longer required or recommended around the arguments of a function called as a statement -- for example, you can now do: print "Hello world!"

    - Tweaked formatting of numbers when converting to strings. Now displays all integer values in full integer form; uses exponential notation for other numbers > 1E10, or < -1E10, or in the range -1E-6 to 1E6; and for any other numbers, displays in standard notation with 1-6 digits past the decimal place.

    - New string.split(self, delimiter=" ", maxCount=null) method splits a string into a list by delimiter with at most maxCount entries.

    - New list.join(self, delimiter=" ") intrinsic joins a list into a string using the given delimiter.

    - New replace(oldval, newval, maxCount) intrinsic works on strings, lists, and maps; parameters are old value (to be replaced), new value (to replace it with), and optionally a maximum number of replacements to make (if omitted, then all occurrences are replaced). Lists and maps are mutated in place.

    - New log(x, base=10) intrinsic finds the logarithm of the given number with the given base (defaults to 10), i.e., the number y such that base^y == x.

    - Added an "isa" operator for runtime type checking. Usage: `a isa b`, where a is any value, and b is: list, map, number, string, funcRef, or some other map. In the case of maps, this walks the __isa chain as you would expect. Evaluates to 1 if `a` is of the type specified by `b`, or 0 otherwise.

    - Strings now support subtraction, which is the inverse operation of string addition (concatenation): if the left-hand side string ends with the right-hand side string, then the latter is stripped off in the result; otherwise the left-hand string is returned as it is. Example: "foo.txt" - ".txt" == "foo".

    - New intrinsic "version" returns a map containing information about MiniScript and its host app: numeric version of miniscript and host, build date in YYYY-MM-DD format, and host name and info (e.g. URL).

    - New special identifier "super" can be used to invoke a function on the base class, e.g., `super.foo(42)` invokes `foo` on the base class, while keeping `self` bound to the same value as in the current function. ("super" and "self" are pseudo-keywords: technically identifiers, but with special built-in behavior.)

    - Host apps can now set an "assignment override function" on any ValMap, allowing a bit of native code to run when user code assigns a value in that map.

    - Fixed a failure of the "not" operator to work with lists and maps.
     
    zyzyx likes this.
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    Don't want to spam my own thread too much :p, but this is so much fun I have to share.

    I'm working recently on Mini Micro, which is an 80s-style virtual computer that uses MiniScript both for the programming language, and for the command language at the prompt. I've just added support for sprites, and added a demo to the /sys/demo directory which is surprisingly fun to play with!



    To try it out:
    1. Go to https://miniscript.org/MiniMicro
    2. Enter
      cd "/sys/demo"
      (the quotation marks are required)
    3. Enter
      load "spriteDemo"
      (required again)
    4. run
    Use the arrow keys to move; press Esc when done. Then, if you like, use the
    edit
    command to monkey with the code!

    Edit: Mini Micro now has its own thread in the Works in Progress forum.
     
    Last edited: Jun 22, 2019
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,347
    cannot copy paste commands.. i think i've seen some threads for workarounds with unity webgl.
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    Yes, I delved into those here. They don't work for the code editor, because it's not an input field. :( (They work by basically positioning a native input field on top of the Unity one, cleverly matching the font etc. so the user maybe doesn't notice... but since the behavior of a code editor is quite different, they would notice in this case.)

    I could maybe replace the MiniScript code editor entirely with an Ace code editor like used on the Try-It page. That's a possibility for the future. But I still wouldn't have a reliable way to save your code across runs. I could use browser data, but that's likely to be lost when you switch browsers or clean your cache. The only right solution for that would be to save on the server, which means user accounts and logins... bleh.

    For now, the Web version is going to be like the store model: you can dink around on it and run the demos, but it's pretty serious for limited use. What you want is to take one home, i.e., a downloadable version, which is the planned solution (and if anybody wants one before it's officially "ready," just PM me!).
     
  7. ifayad

    ifayad

    Joined:
    Jun 15, 2017
    Posts:
    24
    Hello @JoeStrout , Any chance to include the Mini Micro with the asset ? Is it the same as the command line for Linux/mac ?
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    No, Mini Micro is a big app based on MiniScript; it's not part of MiniScript. It also uses several other assets (NativeFileBrowser for example). So I can't include it or open-source it.

    But can I ask why you would want that, anyway? Mini Micro is free, so if you want to play with it you certainly can whether you have the MiniScript asset or not.
     
  9. ifayad

    ifayad

    Joined:
    Jun 15, 2017
    Posts:
    24
    In the game I'm working on, you have a sort of an in game computer. Initially I wanted to only have a shell prompt, so I repurposed a fully fledged command line interpreter, which is an overkill. Then I had the idea of adding a scripting language (that's why I bought miniscript) where users can write code and execute programs to interact with the environment. The computer has a virtual memory system and all the files and data are stored in a document manager (so users don't have access to your real computer). Long story short, after finding that you have a terminal I thought i'd get rid of my command line interpreter and let miniscript handle everything. So I'm just interested in the command line really. If it's the same as the shell that you implemented in c++, I can port it to c#
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    OK, first, that sounds awesome, and please keep me posted as your game develops, so I can point MiniScript users to it!

    You should indeed be able to ditch your command line interpreter and let MiniScript do it; that's how Mini Micro works. There are just intrinsics and some automatically-run start up code that define things like cd, clear, etc. The only drawback (if you want to call it that) is that, unlike a typical file shell, you have to use quotation marks around any string arguments (like paths or file names). If that really bugs you, you could have a bit of code that sits between the user's input and the MiniScript interpreter that does this for you.

    So give Mini Micro a try (probably best to discuss that over in its thread), and if there's anything in there that would be useful to your game, PM me and I'll be happy to share it.

    This goes for everyone here — I am eager to help you all embed MiniScript into your games, and make it awesome. I have already worked closely with a couple of developers to help them get the most out of it, and I'm happy to do the same for you. The bigger the MiniScript user community gets, the better it is for all the games that use it!
     
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    MiniScript v1.4.1 is now available in the Asset Store! Changes in this release:
    • Fixed a bug that would cause the `break` keyword to throw a compiler error when used before an `else` block. {GitHub issue #2}
    • The split(delim, maxCount) intrinsic now works with a delimiter of empty string; it splits on individual characters, up to the specified count. (Note that if you don't specify maxCount, then using .values would be equivalent and slightly more efficient.) {#1}
    • Fixed a bug where hasIndex on a list would return true for any string argument {#3}.
    • New list.insert(index, value) intrinsic inserts a new value into a list in place. Also works for strings, though in that case a new string is returned (since strings are immutable). {#4}
    • Fixed inconsistent handling of @ (the address-of operator) on the first token of a statement. Especially seen in a REPL, for example: entering `@rnd` should (and now does) display the function summary rather than actually invoking the function. {#5}
    • When you convert a list or map to a sting, and it contains a reference to some other list or map that is also referred to by a global variable, you now see it as the global variable rather than its contents. This makes it much easier to examine such objects, particularly in object-oriented programming where the __isa chain can otherwise be hard to wade through.
    • Fixed an infinite loop that could occur if you constructed an __isa chain containing a loop.
    This is a recommended update for all MiniScript users.
     
    zyzyx likes this.
  12. Yozaro

    Yozaro

    Joined:
    Jun 28, 2015
    Posts:
    54
    Hi! I bought your asset last week and looked into it during the weekend. So far I have implemented a code generator, that looks for certain attributes (such as MSClass, MSMethod, MSEnum) from my code and generates both C# and Miniscript APIs for these.

    Next thing on my todo list is to figure out a nice way to reload scripts while the game is still running. This would allow me to leave a scene, modify and reload the scene's scripts, and then re-enter the updated scene. I think this should be possible with the way the interpreters are done.

    Anyway, good job with Miniscript! It is quite fun and intuitive to work with. I'll add a review to Asset Store later once I'm more familiar with Miniscript.
     
    JoeStrout likes this.
  13. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    Sounds great! I agree, what you're describing should be quite doable. Have fun, and let me know if you run into any issues!
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    I just wrote a new blog post explaining some of the rationale behind MiniScript's design:

    Check out the full post, and feel free to comment here or in the MiniScript forums!
     
    Yozaro, tiggus, aer0ace and 1 other person like this.
  15. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    For anybody who's been using MiniScript on the command line — or wanted to, but couldn't because you're on Windows! — I have good news. Command-line MiniScript is now available for all desktop platforms (Mac/Win/Linux)!

    And while it was previously available for Mac and Linux, today's build includes substantial enhancements for them too, particularly related to file handling.

    See the official announcement here, or download it from here.
     
    zyzyx likes this.
  16. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    For all MiniScript users... or potential MiniScript users... or wanna-be-but-haven't-yet-had-the-opportunity-MiniScript-users:

    I'm hosting a MiniScript Rosetta Code contest, with prizes of $25, $15, and $10 for 1st/2nd/3rd place! All you have to do is implement little Rosetta Code programming tasks in MiniScript. Whoever implements the most by October 15th wins!

    Check out the official announcement here, and if you have any questions, don't hesitate to ask. I intend this to be a fun way for people of all skill levels to get some experience with MiniScript, and help fill out Rosetta Code at the same time. So dive in, and have fun!
     
    zyzyx likes this.
  17. kraihd

    kraihd

    Joined:
    Sep 10, 2015
    Posts:
    15
    Are you considering to make this script ready for Burst compiler?
    Burst is a great way for high performance processing (particularly movement of projectiles or enemies), and I guess that it is very synergistic with the concept of MiniScript.
    If realized, it would be defenitely powerful.
     
  18. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,134
    I haven't really thought much about how the Burst compiler might be applied to MiniScript. That's an interesting idea!