How to use Lua scripts

Learn here how to create and use plugins.

Moderator: Plugin Moderators

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 769
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

How to use Lua scripts

Post by FranchuFranchu » Fri Oct 19, 2018 2: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 28 times
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

User avatar
Mg3094066
Inhabitant of a Galaxy Cluster
Reactions:
Posts: 2963
Joined: Sun May 28, 2017 1:50
Location: United Mexican States
Plugins: Show
Version: Beta
Phone model: LG H320mb 5.0.1

Re: How to use Lua scripts

Post by Mg3094066 » Fri Oct 19, 2018 6:52

FranchuFranchu wrote:
Fri Oct 19, 2018 2: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?
Making Ice cubes intead of pee since... yesterday :'v

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 769
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Re: How to use Lua scripts

Post by FranchuFranchu » Fri Oct 19, 2018 12:04

It shows a toast each month
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

ElephantEthan
Inhabitant of a Megacity
Reactions:
Posts: 299
Joined: Sun Aug 26, 2018 14:07
Plugins: Show

Re: How to use Lua scripts

Post by ElephantEthan » Thu Oct 25, 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
Reactions:
Posts: 6853
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Re: How to use Lua scripts

Post by CommanderABab » Thu Oct 25, 2018 20:07

Probably not; sure, why not; why not a sand dune blowing in the wind?
587587Currently using beta 587. 587 What's new? :)
bus routes are supposed to be fixed!!
:cry:

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
CommanderABab
AB
Reactions:
Posts: 6853
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Re: How to use Lua scripts

Post by CommanderABab » Thu Oct 25, 2018 20:08

Yay! A triple negative sentencs!
587587Currently using beta 587. 587 What's new? :)
bus routes are supposed to be fixed!!
:cry:

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

ElephantEthan
Inhabitant of a Megacity
Reactions:
Posts: 299
Joined: Sun Aug 26, 2018 14:07
Plugins: Show

Re: How to use Lua scripts

Post by ElephantEthan » Thu Oct 25, 2018 20:24

CommanderABab wrote:
Thu Oct 25, 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.

ElephantEthan
Inhabitant of a Megacity
Reactions:
Posts: 299
Joined: Sun Aug 26, 2018 14:07
Plugins: Show

Re: How to use Lua scripts

Post by ElephantEthan » Fri Oct 26, 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
Reactions:
Posts: 367
Joined: Sun Jul 22, 2018 17:54
Location: On the edge of a large table
Plugins: Show
Version: Beta
Phone model: A stolen phone

Re: How to use Lua scripts

Post by TheRetroGuy » Tue Nov 06, 2018 1:28

Is it possible to have a Lua app on mobile?

User avatar
CommanderABab
AB
Reactions:
Posts: 6853
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Re: How to use Lua scripts

Post by CommanderABab » Tue Nov 06, 2018 2:03

587587Currently using beta 587. 587 What's new? :)
bus routes are supposed to be fixed!!
:cry:

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
Bearbear65
Inhabitant of a Universe
Reactions:
Posts: 4567
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Xperia™ XZ1 SO-01K

Re: How to use Lua scripts

Post by Bearbear65 » Thu Nov 08, 2018 13:29

CommanderABab wrote:
Tue Nov 06, 2018 2:03
https://play.google.com/store/apps/deta ... .luastudio looks like one.
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)
ImageJust my opinion
Theotown forum authoritarian

Post Reply Previous topicNext topic

Return to “Tutorials and Documentation”

Who is online

Users browsing this forum: No registered users and 1 guest