I would like to run small script programs at run time in unity. For things like experimenting.
Things like:
for(x=1;x<100;x++){
AddNewMonsterAt(x*10,0,0);
}
And various things like that. So what do you think is the best scripting language to link into Unity that will let me call some of my c# functions at run time. And also have things like for loops and so on.
C# itself is the first path. Choosing C# will allow you the most performance because the code will be compiled prior to execution (through a Just-in-Time compiler), but this can potentially allow modders to create malicious scripts and this path is not compatible with AOT platforms like iOS.
Your second path is to choose an interpreted language which wonāt have the risk of malicious code and will run on AOT platforms but will be significantly slower. There are multiple entries on the Asset Store but the ones linked below have either been kept up-to-date or have positive recent reviews.
Lua is fairly easy to implement. I sometimes use the same package what @TonyLi put in the Dialogue System. (And Iām currently not in the front of my Unity-computer so I canāt link it)
It of course depends how much performance you need. It can be slow if you use it for serious update-loop things.
Not automatically, but if itās not a DLL, you can prevent it to call into your system. And of course you design the entire API what is published to the scripting language.
I wouldnāt call it protection against āmalicious codeā, because with DLLs and C# you can inject whatever you want at any time. But it protects against user mistakes.
Like @ mentioned itās more the āautomaticallyā part but I didnāt think about that at the time. Interpreted is much more easy to filter out the possibility of a mod being malicious because you can modify the interpreter to not allow certain instructions while a compiled approach makes it much more difficult to intercept malicious instructions.
The version in the Dialogue System has a lot of fixes. Iād push them to a public repository, but the original author didnāt set one up. If anyone would like a copy of the updated LuaInterpreter, let me know and Iāll make a unitypackage. There are other free Lua packages on the Asset Store, too, such as MoonSharp, which Ryiah linked above. And thereās also @JoeStrout 's Miniscript, also linked above.
Paging @JoeStrout . MiniScript seems like a good fit here.
If you tightly control what commands your interpreted language has, you can reduce the possibility that someone writes malicious code. For example if you have access to full C#, you can start doing random stuff to the file system. If you only have access to an internal MoveCharacter command, you canāt do much damage to the userās system.
Agreed. If youāre interested, the forum thread is here. Iād be delighted to talk to you about your runtime scripting needs (including why, after writing three chapters of a book about Lua, I scrapped it and started designing MiniScript instead).
Also, you can make lua work in sandbox mode, which only allows access defined commands by user, and basics math.
But you can make it as well having access to system files.
And there are few more modes, which allows less, or more permitted access. For example you can get system time, but you can not read / write files.
Mentioned moonsharp has such options.
I used it not so long ago in sand box mode.
I wanted only custom predefined methods, to be executed.
Therefore, you can not do anything malicious via lua, for example like reflections, or attaching dll etc.
I have just started to use Lua becasue Z-Wave uses it. It must be the most backward language in existing. I mean, this is how you foreach a array in that language.
local devices = {19}
switchedOnDevices = {}
for i, device in ipairs(devices) do
if luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device) == "1" then
table.insert(switchedOnDevices, device)
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, device)
end
end
or that static table.insert to mimic List behaviour. Interesting
Just for interested in programming languages family
lua is roughly at 1 oāclock, next to PHP.
C is at 10-11oāclock
C++ at 8-9oāclock
C# at 3oāclock
Yes, youāve pretty much got it. Lua looks attractive at first, but when you start to see the ugly, you realize it goes very deep. All variables global by default, arrays much harder to use than they should be, etc. I know it does the job it was intended to do, but I found I just couldnāt stomach it after a while.
MiniScript was designed from the beginning to have a clean, straightforward syntax, drawing the best features from modern languages like Python, C#, and VB.NET.
Itās interesting to ponder where it would fall in the language tree above. ā¦But now that I look at it, Iām not sure that diagram is very useful. It has Visual Basic and VB.NET at opposite sides of the tree, even though the latter is derived directly from the former and has almost the same syntax. It shows Xojo most closely related to Delphi, even though Xojo is also based on Visual Basic and has nothing at all in common with Pascal. It shows C, C++, and ObjC having nothing (!) in common, though in reality both C++ and ObjC were derived directly from C. Go figure. ĀÆ_(ć)_/ĀÆ
Yep there may be few discrepancies. Perhaps would be needed more research to find most accurate graph.
There are some overlaps and cross shares across languages too, as far I am aware. Which perhaps is hard to picture on radial graph. I know there is many graphs, but If anyone has better, what more important more reliable graph representation, it would be nice to share it.
I might be popular with the German audience because the verbs are at the end! (Not so good for intellisense though!) One could also have an āifā rule as condition ? action and a āwhileā rule as condition # action. Else might be ~?
I think a class would just be implemented as exceptions. Just set something equal to a base class (default being Object) and add exceptions/additions such as:
Dog = Animal @ {
sound = "woof";
legs = 4;
}
(This also works if you think of it as a union between Animal class and an abstract class.)
Then you would say dog = new Dog; sound dog : print. (As in sound of dog). OK, now Iāve got carried away!