Script

From Legends of Aria Admin and Modding Wiki
Revision as of 19:24, 5 November 2016 by Yorlik (talk | contribs) (Basics)
Jump to: navigation, search

Basics

Scripts in Shards Online are files written in Lua ending with .lua and containing the Lua code which does what your script should do.

A super primitive script
helloworld.lua

print ("Always look at the bright side of life, and yes, 'Hello World!'")

This script being put into your mods scripts folder by itself does nothing.

To have your script doing something it needs to be attached to a some Game Object (GameObj), like an NPC, a crate, a rock, anything that can exist in the SO world.

So lets create an object and attach the script to it. You can do that with the "GodInfo" window on the bhavior side. An attached behavior is nothing but a synonym for an attached script.

Scripts can contain other scripts using the require function.

When doing so, you will see the text being printed to the server console which teaches us one thing:

Once a script gets attached to an object it runs immediately.

Attach the script to a second object and see the message again - as often as you attach it to an object.

You can attach a script to many different objects, but only once to any given object.

If then, you decide to backup and restart your server (/backup and /restart) and thus the object with the attached script gets saved, you will see the text again in your console after restart, exactly one time per object which teaches us:

When an object gets loaded from backup all scripts on it run once.

So how can scripts add any persistent functionality to an object - do we have to keep them running or what? Hell, No ! A running script would block the server permanently, what we want is the script to wait for things to happen it should respond to. Scripts are mostly event controlled, the whole script architecture is based on events