Scripting API

The ElvenShade API is easy to use. Here's all the info you need to modify your world using scripts.

Getting Started

Scripting in ElvenShade is done in the JavaScript programming language. There is a wealth of information and tutorials online on how to use this language. This post focuses on the additional functions provided by ElvenShade to interact with your world.

When you create a world in ElvenShade, there are 3 types of scripts you can write:

Server Scripts

Server scripts run on the server for each user. Your sensitive game logic should go here to avoid cheating/hacking. The APIs used by this type of script are geared toward controlling the state of the game world, such as damaging another users’s health or acquiring a new item.

Client Scripts

Client scripts run on the client for each user. The APIs used by this type of script are geared toward controlling the user interface and making requests to server scripts.

Mod Scripts

Mod scripts are also client scripts, however they exist only for the specific user. The APIs used by this type of script are the same as the client script APIs. These scripts are ideal for using admin APIs. If provided with an interface to do so, end-users can create client side mods.

Server Script APIs

Client and Mod Script APIs

Scripts are always in “strict mode”.

Script executions (either when the script is started or when a queued function call is made) will timeout if they run for more than 1000ms. For a smooth experience, it is recommended to keep script executions under 100ms. Remember users on slower devices will take longer to execute them. Execution duration is automatically logged to the console. There is also a recursion limit of 500 within an execution.

thisScriptName //string

The name of the current script.

es.time //float

The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the application.

es.console.log(string message)

Logs a message to any subscribed consoles

es.console.onLog(string script, string func, object[] args = null)

Listen for a console log with specified callback and optionally supply a list of arguments. Log message will be added to the end of the argument list. onLog callbacks are not added to the script execution queue but are executed in parallel. They do not log the duration of execution (thus avoiding an infiite loop). You should also not use es.console.log(message) within an onLog callback for the same reasons.

es.console.stopOnLog(string script, string func)

Stop listening for a console log

es.ui.addGump(string id) //ESGump : ESUIContainer : ESUIElement

Adds a gump (Graphical User Menu Popup) to the screen. Returns a reference to itself.

es.ui.removeGump(string id)

Removes a gump

es.ui.getGump(string id) //ESGump : ESUIContainer : ESUIElement

Gets a gump. Returns the reference to it.

(ESUIContainer).getElement(string id) //ESUIElement
(ESUIContainer).addText(string id) //ESText : ESUIElement
(ESUIContainer).addText(string id, string text) //ESText : ESUIElement
(ESUIContainer).addButton(string id) //ESButton : ESUIContainer : ESUIElement
(ESUIContainer).addInput(string id) //ESInput : ESUIElement
(ESUIContainer).addPanel(string id) //ESPanel : ESUIContainer : ESUIElement
(ESUIContainer).addScrollList(string id) //ESScrollList : ESUIElement
(ESUIElement).anchorLeft // float
(ESUIElement).anchorBottom // float
(ESUIElement).anchorRight // float
(ESUIElement).anchorTop // float
(ESUIElement).offsetLeft // float
(ESUIElement).offsetBottom // float
(ESUIElement).offsetRight // float
(ESUIElement).offsetTop // float
(ESUIElement).background // int
(ESUIElement).r // float
(ESUIElement).g // float
(ESUIElement).b // float
(ESUIElement).a // float
(ESUIElement).active // bool
(ESUIElement).remove()
(ESUIElement).setAnchors(float left, float bottom, float right, float top) //ESUIElement
(ESUIElement).setOffsets(float left, float bottom, float right, float top) //ESUIElement
(ESUIElement).setBackgroundImage(int id) //ESUIElement
(ESUIElement).setBackgroundColor(float r, float g, float b, float a) //ESUIElement
(ESUIElement).setBackground(int id, float r, float g, float b, float a) //ESUIElement
(ESUIElement).setActive(bool active) //ESUIElement
(ESText).text //string
(ESText).align //string
(ESText).overflow //string
(ESText).wordWrap //bool
(ESText).setText(string text) //ESText : ESUIElement
(ESText).setAlign(string align) //ESText : ESUIElement
(ESText).setOverflow(string overflow) //ESText : ESUIElement
(ESText).setWordWrap(bool wordWrap) //ESText : ESUIElement
(ESButton).onClick(string script, string func, object[] args = null) //ESButton : ESUIContainer : ESUIElement
(ESButton).stopOnClick(string script, string func) //ESButton : ESUIContainer : ESUIElement
(ESInput).text //string
(ESInput).placeholder //string
(ESInput).multiLine //bool
(ESInput).wordWrap //bool
(ESInput).onEndEdit(string script, string func, object[] args = null) //ESInput : ESUIElement
(ESInput).stopOnEndEdit(string script, string func) //ESInput : ESUIElement
(ESInput).onSubmit(string script, string func, object[] args = null) //ESInput : ESUIElement
(ESInput).stopOnSubmit(string script, string func) //ESInput : ESUIElement
(ESInput).onSelect(string script, string func, object[] args = null) //ESInput : ESUIElement
(ESInput).stopOnSelect(string script, string func) //ESInput : ESUIElement
(ESInput).onDeselect(string script, string func, object[] args = null) //ESInput : ESUIElement
(ESInput).stopOnDeselect(string script, string func) //ESInput : ESUIElement
(ESInput).setText(string text) //ESInput : ESUIElement
(ESInput).setPlaceholder(string text) //ESInput : ESUIElement
(ESInput).setMultiLine(bool multiLine) //ESInput : ESUIElement
(ESInput).setWordWrap(bool wordWrap) //ESInput : ESUIElement
(ESScrollList).itemCount //int
(ESScrollList).setItemCount(int count) //ESScrollList : ESUIElement
(ESScrollList).getItem(int index) //ESScrollList : ESUIElement