Difference between revisions of "Script"
(Created page with "== Basics == Scripts in Shards Online are files written in Lua ending with <tt>.lua</tt> and containing the Lua code which does what your script should do. A super primit...") |
|||
Line 3: | Line 3: | ||
A super primitive script | A super primitive script | ||
− | <tt>helloworld.lua</tt> | + | <br><tt>helloworld.lua</tt> |
<syntaxhighlight lang = lua> | <syntaxhighlight lang = lua> | ||
print ("Always look at the bright side of life, and yes, 'Hello World!'") | print ("Always look at the bright side of life, and yes, 'Hello World!'") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | 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. | ||
+ | |||
+ | 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 an object only once. | ||
+ | |||
+ | If then, you decide to backup and restart you 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. |
Revision as of 19:17, 5 November 2016
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.
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 an object only once.
If then, you decide to backup and restart you 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.