Lua chatbox

The Lua scripting language allows you to give your plugin more advanced features.
Previous topicNext topic
User avatar
ian`
Metropolitan
Reactions:
Posts: 117
Joined: 04 Apr 2020, 15:36
Location: 日本
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Lua chatbox

Post by ian` »

rjroldan1 wrote: 17 Oct 2020, 15:51 can the value of a variable that is in process such as in script:update() would be stored insidr tables even if it is pre-defined from local declaration .... I think it the game should read and used the value of the variable that is in pre-defined in var-declaration than the saved values
Yeah, it's possible. As the saveState() is a function, it will call all body of the function. Please notice the upvalue of vars.

Code: Select all    Reset

local foo -- declare empty variable local function getStorage() return Util.optStorage(TheoTown.getStorage(), key) end local function saveState() local storage = getStorage() storage.foo = foo end local function loadState() local storage = getStorage() foo = storage.foo or 'value' -- if storage.foo is nil, foo will be set to 'value'. if storage.foo isn't nil, foo will be set to storage.foo end function script:init() loadState() end function script:nextMonth() foo = 'anotherValue' saveState() -- will store the new value of foo to storage.foo end
Lua editor
Run
I think it will be recommended if the saveState() only call after the value of variable is changed, so it will not affect performance because it don't call useless functions.
rjroldan1 wrote: 17 Oct 2020, 18:48 Can we use gui on building taps? As substitute to the onClick notif or its info itself
For simply method, you can use script:finishInformationDialog(x,y,level,dialog)

Code: Select all    Reset

-- script.lua function script:finishInformationDialog(x,y,_,dialog) dialog.title:setText(...) dialog.content:addListBox{...} dialog.controls:addButton{...} end
Lua editor
Run

Code: Select all    Reset

// building.json [ { "id":"buildingId", // body "script":"script.lua" } ]
JSON checker
Check
:bc
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

ian` wrote: 18 Oct 2020, 03:42
rjroldan1 wrote: 17 Oct 2020, 18:48 Can we use gui on building taps? As substitute to the onClick notif or its info itself
For simply method, you can use script:finishInformationDialog(x,y,level,dialog)

Code: Select all    Reset

-- script.lua function script:finishInformationDialog(x,y,_,dialog) dialog.title:setText(...) dialog.content:addListBox{...} dialog.controls:addButton{...} end
Lua editor
Run

If those dialog are exactly the same as List box in GUI give me some example im clueless what is inside the object "{}"
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
User avatar
ian`
Metropolitan
Reactions:
Posts: 117
Joined: 04 Apr 2020, 15:36
Location: 日本
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Lua chatbox

Post by ian` »

you can look at gui compendium, there is a complete explanation of gui.
:bc
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

ian` wrote: 18 Oct 2020, 17:43 you can look at gui compendium, there is a complete explanation of gui.
Based in the docs its only visible after the building/road was built
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
User avatar
ian`
Metropolitan
Reactions:
Posts: 117
Joined: 04 Apr 2020, 15:36
Location: 日本
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Lua chatbox

Post by ian` »

So you want make a thing like gui example in Dev tool plugin by Lobby?

Actually you can look at gui example post for the complete code.

Code: Select all    Reset

local function showDialog() -- Body of dialog that will show when tool is clicked end function script:event(x,y,lvl,event) if event == Script.EVENT_TOOL_ENTER then GUI.get'cmdCloseTool':click() -- close the build mode showDialog() -- call the dialog end end
Lua editor
Run
:bc
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

ian` wrote: 18 Oct 2020, 18:38 So you want make a thing like gui example in Dev tool plugin by Lobby?

Actually you can look at gui example post for the complete code.

Code: Select all    Reset

local function showDialog() -- Body of dialog that will show when tool is clicked end function script:event(x,y,lvl,event) if event == Script.EVENT_TOOL_ENTER then GUI.get'cmdCloseTool':click() -- close the build mode showDialog() -- call the dialog end end
Lua editor
Run


I used

Code: Select all    Reset

function script:finishInformationDialog(x,y,_,dialog) dialog.title:setText("Haha") dialog.content.parent:addListBox{ x = 10, y = 10, width = -10, height = -10 } local entry = listBox:addCanvas{h=30} local lbl = entry:addLabel{ text = 'This is entry ' width = -30 } local cmd = entry:addButton{ x = -35, width = 30, icon = Icon.OK, onClick = function() Debug.toast('Clicked on entry ') end } dialog.controls:addButton{ x = -35, width = 30, icon = Icon.OK, onClick = function() Debug.toast('Clicked on entry ') end } return false end
Lua editor
Run
But nothing shows
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

I'd also used :

Code: Select all    Reset

function script:finishInformationDialog(x,y,_,dialog) dialog.title:setText("Haha") dialog.content:addListBox{ x = 10, y = 10, height = -10, width = -10 } dialog.controls:addButton{ x = -35, width = 30, icon = Icon.OK, onClick = function() Debug.toast('Clicked on entry '..i) end } end
Lua editor
Run
These works but doesn't have canvas neither parent and how to add list item inside of these?
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

Code: Select all    Reset

Drawing.drawText("E!", 30, 30) function script:buildCityGUI() local function aci() local dialog = GUI.createDialog { title = "Advanced city infomationn" } local layout = dialog.content:addLayout{ vertical = true, spacing=2 } local panel = addPanel { width = 30, height = 30 } local function addLine(label, height) local line = layout:addLayout{height = height} line:addLabel{text = label, w = 60} return line:addLayout{ x = 62 } end local line = addLine("City name", 10) local textframe = dialog.content:addTextFrame { text = [[E!]] } end local sidebar = GUI.get('sidebarLine') local button = sidebar:getFirstPart():addButton { width = 20, height = 20, onClick = function(self) aci() end } end --But why is the text frame not showing in the dialog?
Lua editor
Run
You do not have the required permissions to view the files attached to this post.
Last edited by 1Code on 19 Oct 2020, 20:32, edited 1 time in total.
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

Screenshot_20201019-215723_TheoTown.png
You do not have the required permissions to view the files attached to this post.
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

And also, why is the above code isn't working*

Code: Select all    Reset

function script:update() --*inside here end
Lua editor
Run
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

Jeremiah Stephens wrote: 19 Oct 2020, 20:32 Screenshot_20201019-215723_TheoTown.png
My question is why did you put dialog.content:addButton{} if you want to show only the textframe?
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

Based on what I've understood in your codes you want to have text inside the button?

Code: Select all    Reset

local line = addLine('City name:', 10) line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function() Debug.toast('City Name') end }
Lua editor
Run
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

rjroldan1 wrote: 20 Oct 2020, 06:15 Based on what I've understood in your codes you want to have text inside the button?

Code: Select all    Reset

local line = addLine('City name:', 10) line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function() Debug.toast('City Name') end }
Lua editor
Run
Still doesn't work

Code: Select all    Reset

Drawing.drawText("E!", 30, 30) function script:buildCityGUI() local function aci() local dialog = GUI.createDialog { title = "Advanced city infomationn" } local layout = dialog.content:addLayout{ vertical = true, spacing=2 } local function addLine(label, height) local line = layout:addLayout{height = height} line:addLabel{text = label, w = 60} return line:addLayout{ x = 62 } end local line = addLine('City name:', 10) line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function(self) Debug.toast('City Name') end } end local sidebar = GUI.get('sidebarLine') local button = sidebar:getFirstPart():addButton { width = 20, height = 20, onClick = function(self) aci() end } end
Lua editor
Run
Screenshot_20201020-141627_TheoTown.png
You do not have the required permissions to view the files attached to this post.
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

Sorry i forgot it's...

Code: Select all    Reset

local line = dialog:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function() Debug.toast('City Name') end }
Lua editor
Run
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

Code: Select all    Reset

Drawing.drawText("E!", 30, 30) function script:buildCityGUI() local function aci() local dialog = GUI.createDialog { title = "Advanced city infomationn" } --local root = GUI.getRoot() local layout = dialog.content:addLayout{ vertical = true, spacing=2 } local panel = addPanel { width = 30, height = 30 } local function addLine(label, height) local line = layout:addLayout{height = height} line:addLabel{text = label, w = 60} return line:addLayout{ x = 62 } end local line = dialog:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function() Debug.toast('City Name') end } line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function(self) Debug.toast('City Name') end } end local sidebar = GUI.get('sidebarLine') local button = sidebar:getFirstPart():addButton { width = 20, height = 20, onClick = function(self) aci() end } end
Lua editor
Run
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

Screenshot_20201022-171010_TheoTown.png
You do not have the required permissions to view the files attached to this post.
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

Code: Select all    Reset

Drawing.drawText("E!", 30, 30) function script:buildCityGUI() local function aci() local dialog = GUI.createDialog { title = "Advanced city infomationn" } --local root = GUI.getRoot() local layout = dialog.content:addLayout{ vertical = true, spacing=2 } local panel = addPanel { width = 30, height = 30 } local function addLine(label, height) local line = layout:addLayout{height = height} line:addLabel{text = label, w = 60} return line:addLayout{ x = 62 } end local line = addLine('button',26) line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function() Debug.toast('City Name') end } line:addButton{ icon = Icon.CITY, x = -35, width = 25, text = 'City Name', onClick = function(self) Debug.toast('City Name') end } end end
Lua editor
Run

I edited some @Jeremiah Stephens i dont know how about side bar
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
1
1Code
Inhabitant of a Megacity
Reactions:
Posts: 283
Joined: 30 Jan 2020, 14:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by 1Code »

Screenshot_20201022-205028_TheoTown.png
You do not have the required permissions to view the files attached to this post.
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

Check Gui Compendium @Jeremiah Stephens
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 722
Joined: 17 Jul 2017, 14:16
Location: Philippines
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua chatbox

Post by Hadestia »

@Lobby is there any Runtime modules that detects user inputs in all Textfields?

im making a text sensor that will censored all inappropriate words that the user used, this will be nice addon for the game if you want too :)
 ! Message from: Hadestia
Visit my YouTube channel:
https://youtube.com/channel/UC5qG-r8y21036JZbGRClbdQ
Previous topicNext topic