Entity Tutorial 2: Simple Script: Difference between revisions

From SkyCorp Global
Jump to navigation Jump to search
(Created page with ".")
 
No edit summary
Line 1: Line 1:
.
In this tutorial, we will upgrade the Shiny Gem object from Tutorial 1. Now instead of using a literal string for the description, the description will be generated by LUA code.
 
Generally, if only returning a static string, a string literal like in the previous tutorial should be used due to performance reasons.  However, this will demonstrate the simplest possible LUA code before we expand upon it in the next tutorial.
 
Definition Upgrade
 
Now for '''description''', we set the parameter '''programString''' to true, to indicate that there is a description() function in the lua code that can be called for the description.  It is a 'string' because that is the return type of '''description()'''.  Other parameters might be '''programBoolean''', '''programVoid''', etc.  See the reference docs for the return type.
 
There is one other new parameter in the JSON, something called '''luac'''.  That is the base64 version of the compiled lua program.  Let's generate that next.
 
JSON before LUAC
 
Writing the LUA code
 
We create a simple LUA program in a folder on our HDD and name it shinierGem.lua:
 
LUA Code
 
If we just try to run this code from the command line, it won't be overly interesting:
> lua shinierGem.lua                                                       
>
Nothing happens.  This is because the game calls the description() function, whereas nothing is calling the description function.  We could quickly hack this just for quick testing purposes by adding a call to description()
 
JSON after LUAC
 
That will be

Revision as of 04:47, 21 December 2017

In this tutorial, we will upgrade the Shiny Gem object from Tutorial 1. Now instead of using a literal string for the description, the description will be generated by LUA code.

Generally, if only returning a static string, a string literal like in the previous tutorial should be used due to performance reasons. However, this will demonstrate the simplest possible LUA code before we expand upon it in the next tutorial.

Definition Upgrade

Now for description, we set the parameter programString to true, to indicate that there is a description() function in the lua code that can be called for the description. It is a 'string' because that is the return type of description(). Other parameters might be programBoolean, programVoid, etc. See the reference docs for the return type.

There is one other new parameter in the JSON, something called luac. That is the base64 version of the compiled lua program. Let's generate that next.

JSON before LUAC

Writing the LUA code

We create a simple LUA program in a folder on our HDD and name it shinierGem.lua:

LUA Code

If we just try to run this code from the command line, it won't be overly interesting:

> lua shinierGem.lua                                                       
>

Nothing happens. This is because the game calls the description() function, whereas nothing is calling the description function. We could quickly hack this just for quick testing purposes by adding a call to description()

JSON after LUAC

That will be