How to use Lua scripts

The Lua scripting language allows you to give your plugin more advanced features.

Moderators: Scenario Moderators, Plugin Moderators

User avatar
FranchuFranchu
Inhabitant of a Country
Posts: 799
Joined: 28 May 2017, 00:07
Location: Freezing in Argentina
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

How to use Lua scripts

#1

Post by FranchuFranchu » 19 Oct 2018, 02:42

Now Lua can be used in TheoTown. Lua is a real proggraming language. To learn it, read this.

To include a Lua file in your plugin, use this:

Code: Select all

"script":"file.lua",
The file has to be in the same directory as your JSON.
The Lua code can be this:

Code: Select all

function script.nextMonth()
      Debug.toast("Hello Month!")
end
This will show a toast each month.
The full list of the available functions in TheoTown is in https://theotown.com/forum/viewtopic.php?f=41&t=8587.
Attachments
luatest.zip
Credits to Lobby & theotheoderich for the original graphics
(1.73 KiB) Downloaded 1823 times
User avatar
Mg3094066
Inhabitant of a Supercluster
Posts: 3223
Joined: 28 May 2017, 01:50
Location: Venezuelan Republic of Mexico
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to use Lua scripts

#2

Post by Mg3094066 » 19 Oct 2018, 06:52

FranchuFranchu wrote: 19 Oct 2018, 02:42 Now Lua can be used in TheoTown. Lua is a real proggraming language. To learn it, read this.

To include a Lua file in your plugin, use this:

Code: Select all

"script":"file.lua",
The file has to be in the same directory as your JSON.
The Lua code can be this:

Code: Select all

function script.nextMonth()
      Debug.toast("Hello Month!")
end
This will show a toast each month.
The full list of the available functions in TheoTown is in https://theotown.com/forum/viewtopic.php?f=41&t=8587.
Ummm... What does the Lua test?
User avatar
FranchuFranchu
Inhabitant of a Country
Posts: 799
Joined: 28 May 2017, 00:07
Location: Freezing in Argentina
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to use Lua scripts

#3

Post by FranchuFranchu » 19 Oct 2018, 12:04

It shows a toast each month
User avatar
ElephantEthan
Inhabitant of a Megacity
Posts: 294
Joined: 26 Aug 2018, 14:07
Plugins: Showcase Store

Platform

Re: How to use Lua scripts

#4

Post by ElephantEthan » 25 Oct 2018, 18:29

• Do lua scripts need a building to function? (like fun functionality)
• Can lua scripts be attached to anything? (buildings, terrain, trees, cars)
• How would one make a script that replaces a grass tile with a sand tile?
User avatar
CommanderABab
AB
Posts: 11273
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to use Lua scripts

#5

Post by CommanderABab » 25 Oct 2018, 20:07

Probably not; sure, why not; why not a sand dune blowing in the wind?
User avatar
CommanderABab
AB
Posts: 11273
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to use Lua scripts

#6

Post by CommanderABab » 25 Oct 2018, 20:08

Yay! A triple negative sentencs!
User avatar
ElephantEthan
Inhabitant of a Megacity
Posts: 294
Joined: 26 Aug 2018, 14:07
Plugins: Showcase Store

Platform

Re: How to use Lua scripts

#7

Post by ElephantEthan » 25 Oct 2018, 20:24

CommanderABab wrote: 25 Oct 2018, 20:08 Yay! A triple negative sentencs!
Your post contains so much negativity that it's actually positive :lol: although I'm not sure if I understand the land one.
User avatar
ElephantEthan
Inhabitant of a Megacity
Posts: 294
Joined: 26 Aug 2018, 14:07
Plugins: Showcase Store

Platform

Re: How to use Lua scripts

#8

Post by ElephantEthan » 26 Oct 2018, 19:23

Alright, I attached a script to an animation and it works, even if I didn't use the animation. I got the script to run when you open the game. Really cool stuff!
User avatar
TheRetroGuy
Inhabitant of a Conurbation
Posts: 433
Joined: 22 Jul 2018, 17:54
Location: On the edge of a large table
Plugins: Showcase Store
Version: Beta

Platform

Re: How to use Lua scripts

#9

Post by TheRetroGuy » 06 Nov 2018, 01:28

Is it possible to have a Lua app on mobile?
User avatar
CommanderABab
AB
Posts: 11273
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to use Lua scripts

#10

Post by CommanderABab » 06 Nov 2018, 02:03

User avatar
Bearbear76
Former Bearbear65
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to use Lua scripts

#11

Post by Bearbear76 » 08 Nov 2018, 13:29

To be honest I don't like any of the apps that are available
In the store. Rather use a PC or just use a normal text editor that supports Lua (i.e. QuickEdit)
User avatar
Hadestia
Inhabitant of a Megalopolis
Posts: 727
Joined: 17 Jul 2017, 16:16
Location: Philippines
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: How to use Lua scripts

#12

Post by Hadestia » 22 Dec 2019, 14:04

Its like a java 😀
User avatar
Bearbear76
Former Bearbear65
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to use Lua scripts

#13

Post by Bearbear76 » 23 Dec 2019, 02:08

rjroldan1 wrote: 22 Dec 2019, 14:04 Its like a java 😀
Not really like Java.
Compared to java Lua is much more forgiving and easy. :lua:
User avatar
JustAnyone
Developer
Posts: 3598
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: How to use Lua scripts

#14

Post by JustAnyone » 23 Dec 2019, 17:08

Also 10x slower.
User avatar
Bearbear76
Former Bearbear65
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to use Lua scripts

#15

Post by Bearbear76 » 24 Dec 2019, 00:03

Lua is still on the fast side though
User avatar
Vincity
Settler
Posts: 1
Joined: 27 Sep 2024, 08:22

Re: How to use Lua scripts

#16

Post by Vincity » 27 Sep 2024, 08:33

"script":"file.lua",
Post Reply Previous topicNext topic

Return to “Lua Scripting”