Lua chatbox

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

Moderator: Plugin Moderators

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#121

Post by rjroldan1 »

Lobby wrote:
Tue Jun 23, 2020 17:24

Code: Select all

-- Let's use a unique, own key for the table that we will create within a storage table
local key = script:getDraft():getId()

-- Let's get our personal storage table within the city storage table (will be created if it doesn't exist)
local table = Util.optStorage(City.getStorage(), key)

-- Let's put something into it; this should still be there after saving the city, ending the game, and then coming back
table.x = 42
Ahmm is the "x" Here from "table.x" Is the name of my variable? One more thing is what should i put inside script.getDraft():getId()? it's my time again to comeback here i want a refresh

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
Lobby
Developer
Reactions:
Posts: 3631
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

Platform

Re: Lua chatbox

#122

Post by Lobby »

Nice comeback!


rjroldan1 wrote:
Fri Oct 16, 2020 9:12
Ahmm is the "x" Here from "table.x" Is the name of my variable?
The x is the name of the "variable" that is stored inside the table. For illustration how tables work (they are basically containers that contain variables, so to speak):

Code: Select all    Reset

local table = {} -- Creates a new, empty table table.x = 42 print(table.x) -- Will output 42
Interactive Lua editor
Run



rjroldan1 wrote:
Fri Oct 16, 2020 9:12
what should i put inside script.getDraft():getId()?
You can just use it like that in order to use the id of your plugin as key. Alternatively, you can use any unique string, e.g.:

Code: Select all

local key = 'd3020030-1aa0-477e-a04f-0801e3546329'
=^._.^= ∫

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#123

Post by rjroldan1 »

@Lobby 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
Here's my example

Code: Select all    Reset

local var = 0 function script:init() Loadstate() -- loading variable stored ingame end function script:nextMonth() var = var + 50 end function script:update() SaveState() -- saving var values end
Interactive Lua editor
Run

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
ian`
Supporter
Reactions:
Posts: 89
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#124

Post by ian` »

rjroldan1 wrote:
Sat Oct 17, 2020 17: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
Interactive 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:
Sat Oct 17, 2020 20: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
Interactive Lua editor
Run

Code: Select all    Reset

// building.json [ { "id":"buildingId", // body "script":"script.lua" } ]
JSON checker
Check
:bc

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#125

Post by rjroldan1 »

ian` wrote:
Sun Oct 18, 2020 5:42
rjroldan1 wrote:
Sat Oct 17, 2020 20: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
Interactive 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 "{}"

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
ian`
Supporter
Reactions:
Posts: 89
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#126

Post by ian` »

you can look at gui compendium, there is a complete explanation of gui.
:bc

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#127

Post by rjroldan1 »

ian` wrote:
Sun Oct 18, 2020 19: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

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
ian`
Supporter
Reactions:
Posts: 89
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#128

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
Interactive Lua editor
Run
:bc

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#129

Post by rjroldan1 »

ian` wrote:
Sun Oct 18, 2020 20: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
Interactive 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
Interactive Lua editor
Run
But nothing shows

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#130

Post by rjroldan1 »

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
Interactive Lua editor
Run
These works but doesn't have canvas neither parent and how to add list item inside of these?

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#131

Post by Jeremiah Stephens »

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?
Interactive Lua editor
Run
Attachments
Screenshot_20201019-215723_TheoTown.png
Last edited by Jeremiah Stephens on Mon Oct 19, 2020 22:32, edited 1 time in total.

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#132

Post by Jeremiah Stephens »

Screenshot_20201019-215723_TheoTown.png

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#133

Post by Jeremiah Stephens »

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

Code: Select all    Reset

function script:update() --*inside here end
Interactive Lua editor
Run

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#134

Post by rjroldan1 »

Jeremiah Stephens wrote:
Mon Oct 19, 2020 22:32
Screenshot_20201019-215723_TheoTown.png
My question is why did you put dialog.content:addButton{} if you want to show only the textframe?

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#135

Post by rjroldan1 »

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 }
Interactive Lua editor
Run

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#136

Post by Jeremiah Stephens »

rjroldan1 wrote:
Tue Oct 20, 2020 8: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 }
Interactive 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
Interactive Lua editor
Run
Screenshot_20201020-141627_TheoTown.png

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#137

Post by rjroldan1 »

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 }
Interactive Lua editor
Run

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#138

Post by Jeremiah Stephens »

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
Interactive Lua editor
Run

Jeremiah Stephens
Metropolitan
Reactions:
Posts: 131
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#139

Post by Jeremiah Stephens »

Screenshot_20201022-171010_TheoTown.png

User avatar
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 644
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#140

Post by rjroldan1 »

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
Interactive Lua editor
Run

I edited some @Jeremiah Stephens i dont know how about side bar

.╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────
T.P.C.
Theotown Philippine Corporation
Plugin creator Doesn't had Cities

Post Reply Previous topicNext topic

Return to “Lua Scripting”