Search Unity

Realtime Script Compiler (Lua, JavaScript, C#)

Discussion in 'Scripting' started by Fydar, Jan 27, 2015.

  1. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    I need a way of compiling player made code and run it in game. I have looked at lua Interface and kopiLua and I have no idea how they work. Im using Unity free and developing for Windows PC.
     
    Last edited: Nov 2, 2016
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Lua's nasty. I'd rather subject my users to JavaScript than subject them to that. And C# might be even better than JavaScript (depending on your user base).

    Either of these is quite possible with the built-in stuff. See this answer for example.
     
  3. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    Dosn't that involve the player having to install unity and only work in the editor and unbuilt?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Not sure if you're open to Python, but I did spot this in the Unity Asset store:

    http://u3d.as/content/noam-gat/python-interpreter/1Qb

    I'm a bit biased towards Python for easy implementation of small script tasks, so that might do exactly what you're after, and be easy to expand and maintain, I'm guessing.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, that's not it at all. The two techniques mentioned are for compiling code at runtime — loaded from a file, for example, or a GUI element.
     
  6. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    Woah, I did not expect this much helpful feedback. Thanks JoeStrout and Kurt Dekker. I'm gonna compile the code from a GUI element.
     
  7. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    Last edited: Nov 2, 2016
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Actually, scripting is something I'm thinking a lot about lately... I'm going to need it eventually for mod support in High Frontier, and I'm not particularly satisfied with any of the off-the-shelf options I've found.

    I may end up rolling my own solution. But if anybody wants to collaborate on that, please PM me.
     
  9. Fydar

    Fydar

    Joined:
    Feb 23, 2014
    Posts:
    69
    I done research into kopiLua. It works, it's just... I don't want the player to have to use a colon. I may add some script before the players code to add a ton of functions so the player doesn't have to do them. Yes! Thats what I'll do.

    The reason I think I'm struggling so much with Eval is because I HATE JAVASCRIPT!!!! :D
    C# is a million times better. Well, if you good in it... Thanks for your feedback everyone! If you are going to add mod support or anything. KopiLua! Link: http://www.dannygoodayle.com/2013/05/31/integrating-unity-with-lua-in-two-minutes/
    Easy to do. Looks confusing at first. Not at all once you begin work in it.

    Woah, you made High Frontier? I saw that around but never looked into it. It looks like a Halo/Elysium (The movie) cross thing :D

    Basically the game I'm working towards consist of a programming section, where you program a mech, and then connect online and battle with other peoples programming.
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sounds like a lot of fun. I'm not a big fan of Lua, but for a cool programming game, I'd muscle through it!