User:SuzannaLinn Resident/LuaMovingTo: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
* Rez an object and add a new script as usual. The script editor has a "compiler" drop-down list, at bottom center. Choose "Lua": | * Rez an object and add a new script as usual. The script editor has a "compiler" drop-down list, at bottom center. Choose "Lua": | ||
** LSL: Legacy (LSO2) | ** LSL: Legacy (LSO2) - the good old LSL, with "Mono" unchecked. | ||
** LSL: Mono | ** LSL: Mono - the good old LSL, with "Mono" checked (the usual one). | ||
** Lua - SLua | ** Lua - SLua | ||
** LSL/Luau- LSL, but compiled into VM Luau instead of VM Mono. | ** LSL/Luau - LSL, but compiled into VM Luau instead of VM Mono. | ||
== Libraries == | |||
== Datatypes == | |||
== Events and states == | |||
== The first script == | |||
{| {{KBtable}} | |||
| | |||
<syntaxhighlight lang="lsl2" line> | |||
// the "New Script" (LSL) | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
llSay(0, "Hello, Avatar!"); | |||
} | |||
touch_start(integer total_number) | |||
{ | |||
llSay(0, "Touched."); | |||
} | |||
} | |||
// | |||
</syntaxhighlight> | |||
| | |||
<syntaxhighlight lang="lua" line copy> | |||
-- the "New Script" (SLua - LSL style) | |||
function state_entry() | |||
ll.Say(0, "Hello, Avatar!") | |||
end | |||
function touch_start(total_number) | |||
ll.Say(0, "Touched.") | |||
end | |||
state_entry() | |||
</syntaxhighlight> | |||
| | |||
<syntaxhighlight lang="lua" line> | |||
-- the "New Script" (SLua - Lua style) | |||
function touch_start(total_number) | |||
ll.Say(0, "Touched.") | |||
end | |||
ll.Say(0, "Hello, Avatar!") | |||
</syntaxhighlight> | |||
|} | |||
== Operators == | |||
== If == | |||
== Loops == | |||
== Strings == | |||
== Lists == |
Revision as of 08:43, 15 March 2025
Moving from LSL to SLua
In this section, we will learn how to rewrite our LSL scripts in SLua through a two-step process:
- First, we will translate them into SLua while maintaining a structure as close as possible to the original LSL format (SLua in LSL style).
- Next, we will refine and improve them to take full advantage of Lua’s capabilities (SLua in Lua style).
To follow this section effectively, a basic understanding of Lua is required, as covered in the previous two sections.
Using SLua in the beta grid
These are the steps to follow before starting to script in SLua:
- Install the "Second Life Project Lua Editor" viewer, from: https://releasenotes.secondlife.com/viewer.html. This is a different viewer, with a different icon, than the "Second Life Viewer". We can keep our usual viewer for the main grid and use this one for the beta grid.
- Access the Beta Grid (Aditi), explained in: https://lindenlab.freshdesk.com/support/solutions/articles/31000156725-accessing-aditi
- Teleport to one of the four regions that have SLua activated. It doesn't work in the other regions. Sometimes one or two of these regions are offline, try another one if you can't tp or login:
- Rez an object and add a new script as usual. The script editor has a "compiler" drop-down list, at bottom center. Choose "Lua":
- LSL: Legacy (LSO2) - the good old LSL, with "Mono" unchecked.
- LSL: Mono - the good old LSL, with "Mono" checked (the usual one).
- Lua - SLua
- LSL/Luau - LSL, but compiled into VM Luau instead of VM Mono.
Libraries
Datatypes
Events and states
The first script
// the "New Script" (LSL)
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}
//
|
-- the "New Script" (SLua - LSL style)
function state_entry()
ll.Say(0, "Hello, Avatar!")
end
function touch_start(total_number)
ll.Say(0, "Touched.")
end
state_entry()
|
-- the "New Script" (SLua - Lua style)
function touch_start(total_number)
ll.Say(0, "Touched.")
end
ll.Say(0, "Hello, Avatar!")
|