How to use Lua scripts

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

Moderator: Plugin Moderators

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 792
Joined: Sun May 28, 2017 0:07
Location: On an xkcd binge
Plugins: Show
Version: Beta

Platform

Plugin Creator

How to use Lua scripts

#1

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 148 times
Did you know you can't blink while smiling :) ?

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

Plugin Creator

Platform

Re: How to use Lua scripts

#2

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?
I want my diamonds you get the plugins free or not :bd

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 792
Joined: Sun May 28, 2017 0:07
Location: On an xkcd binge
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: How to use Lua scripts

#3

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

It shows a toast each month
Did you know you can't blink while smiling :) ?

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

Platform

Re: How to use Lua scripts

#4

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: 7885
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: How to use Lua scripts

#5

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

Probably not; sure, why not; why not a sand dune blowing in the wind?
770!770Currently using alpha 770. 770 What's new? :)
Need plugins dialog!!
:)

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

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

Platform

Plugin Creator

Re: How to use Lua scripts

#6

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

Yay! A triple negative sentencs!
770!770Currently using alpha 770. 770 What's new? :)
Need plugins dialog!!
:)

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

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

Platform

Re: How to use Lua scripts

#7

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: 294
Joined: Sun Aug 26, 2018 14:07
Plugins: Show

Platform

Re: How to use Lua scripts

#8

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: 422
Joined: Sun Jul 22, 2018 17:54
Location: On the edge of a large table
Plugins: Show
Version: Beta
Phone model: A stolen phone

Platform

Re: How to use Lua scripts

#9

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: 7885
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: How to use Lua scripts

#10

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

770!770Currently using alpha 770. 770 What's new? :)
Need plugins dialog!!
:)

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

User avatar
Ølsken
Former Bearbear65
Reactions:
Posts: 4756
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Samsung S10

Platform

Re: How to use Lua scripts

#11

Post by Ølsken » 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

Post Reply Previous topicNext topic

Return to “Lua Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest