Lua chatbox
-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Thanks! That works nicely!
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
How can I get the y position of a building using City.getBuilding? I can get x by doing
but I don't know how to get y value
Code: Select all
local draft = $ktt_koala01
City.getBuilding(1, draft)
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
ian`
- Metropolitan
- Reactions:
- Posts: 117
- Joined: 04 Apr 2020, 15:36
- Location: 日本
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Code: Select all Reset
local x, y = City.getBuilding(1, draft) local x,y,scale = City.getView() local draft, number = City.getRank()
Lua editor
-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
I knew I was missing something simple. Thanks! 
You do not have the required permissions to view the files attached to this post.
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Builder.BuildBuilding doesn't seem to work with RCI.
Building a park works...
... but if I change it to a residential house, it doesn't work.
I also tried manually placing a zone across the entire map, but it still doesn't want to build residential stuff on it.
Building a park works...
Code: Select all Reset
function script:nextDay() draft = Draft.getDraft("$park01") Debug.toast("Building", draft) if Builder.isBuildingBuildable(draft, 0, 0) then Debug.toast("Buildable!" ) else Debug.toast("Nope!" ) end Builder.buildBuilding(draft, 0, 0, 0) end
Lua editor
Code: Select all Reset
function script:nextDay() draft = Draft.getDraft("$res01") Debug.toast("Building", draft) if Builder.isBuildingBuildable(draft, 0, 0) then Debug.toast("Buildable!" ) else Debug.toast("Nope!" ) end Builder.buildBuilding(draft, 0, 0, 0) end
Lua editor
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Yes, everything is zoned. I also tried adding Builder.buildZone to my script. The zone is built but the house isn't, and the toast still says Nope! which means Lua doesn't see that tile as buildable even if it's zoned.
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
CommanderABab
- AB
- Reactions:
- Posts: 11263
- Joined: 07 Jun 2016, 19:12
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Why don't you try testing for buildable park and if that is true, build the zone and the res01 anyway. 
Is it next to a road?
Is it next to a road?
my avatar:
-
Uncle Koala
- Metropolitan
- Reactions:
- Posts: 142
- Joined: 05 Apr 2020, 12:53
- Location: Pitcairn Islands
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Thanks
, it only builds if there's a road next to that tile. A bit weird, but understandable. I was trying to build RCI stuff just to see if they will be set as "Untouchable" if they are built by Lua. Turns out they won't be set as untouchable. 
Suggestion to devs: please add something like Tile.setUntouchable(x, y)
Suggestion to devs: please add something like Tile.setUntouchable(x, y)
Lua is easy!
Code: Select all
if Car.GoingToCrashIntoEachOther()
then Car.DontCrash
end-
MarioBitMap
- Villager
- Reactions:
- Posts: 15
- Joined: 31 Jul 2020, 20:54
- Location: Spain
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Why isn't my script working?
When playing, I can Access to the menu I've created, but when pressing the button it doesn't shows the next menu.
Thanks in advance!! 
When playing, I can Access to the menu I've created, but when pressing the button it doesn't shows the next menu.
Code: Select all Reset
local function showMenu(dialog) local parent = GUI.get'$menuparent' local d = '$townhall01' local x = City.countBuildings(d) GUI.createMenu{ source = parent, actions = { {icon = Icon.BUILD, text = 'Town Halls:' , onClick = function() Debug.toast(x) end}, } } end local function showDialog() local dialog dialog = GUI.createDialog{ icon = script:getDraft():getPreviewFrame(), title = 'Test 1', text = 'Will this work? lol', width = 250, height = 120, actions = { { id = '$menuparent', icon = Icon.BUILD, text = equis, onClick = function() showMenu(dialog) end, autoClose = false }, } } closeDialog = dialog.close end function script:init() if closeDialog then closeDialog() closeDialog = nil showDialog() end end function script:event(_, _, _, event) if event == Script.EVENT_TOOL_ENTER then GUI.get('cmdCloseTool'):click() showDialog() end end
Lua editor
Code: Select all Reset
[ { "id":"MarioBitMap", "category":"Plugin_Creator", "skills":[{"skill":"Pixel_Artist"},{"skill":"Learning_C++_&_TTJson/Lua"}] } ]
JSON checker
-
Lobby
- Inhabitant of a Supercluster
- Reactions:
- Posts: 3756
- Joined: 26 Oct 2008, 10:34
- Plugins: Showcase Store
Re: Lua chatbox
Hi, I guess it's because of these lines:
City.countBuildings expects a draft rather than the id of a draft. This should work:
Code: Select all
local d = '$townhall01'
local x = City.countBuildings(d)Code: Select all
local d = Draft.getDraft('$townhall01')
local x = City.countBuildings(d)-
MarioBitMap
- Villager
- Reactions:
- Posts: 15
- Joined: 31 Jul 2020, 20:54
- Location: Spain
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Oh I see, thankyou very much!
Just testing the implementation of a new resource as a variable through
Just testing the implementation of a new resource as a variable through
Code: Select all Reset
[ { "id":"MarioBitMap", "category":"Plugin_Creator", "skills":[{"skill":"Pixel_Artist"},{"skill":"Learning_C++_&_TTJson/Lua"}] } ]
JSON checker
-
MarioBitMap
- Villager
- Reactions:
- Posts: 15
- Joined: 31 Jul 2020, 20:54
- Location: Spain
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
... icon = Icon.EXAMPLE, ...
or are Icon.EXAMPLE a type of harcoded resource that can't be added by users?
Thanks in advance!
Code: Select all Reset
[ { "id":"MarioBitMap", "category":"Plugin_Creator", "skills":[{"skill":"Pixel_Artist"},{"skill":"Learning_C++_&_TTJson/Lua"}] } ]
JSON checker
-
ian`
- Metropolitan
- Reactions:
- Posts: 117
- Joined: 04 Apr 2020, 15:36
- Location: 日本
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
I think Icon.EX is hardcoded, because its actually return number.
If you want to add your icons, you still have to write the Json code to making a draft for the image.
If you want to use it on multiple line, you can assigned it to a variable.
If you want to add your icons, you still have to write the Json code to making a draft for the image.
Code: Select all Reset
[ { "id":"iconId", "type":"animation", "frames":[{"bmp":"icon.png", "w":24, "h":24}] } ]
JSON checker
Code: Select all Reset
-- you also can make the Json code from lua and call it with Draft.append local iconImage = [[ [ { "id":"iconId", "type":"animation", "frames":[{"bmp":"icon.png", "w":24, "h":24}] } ] ]] Draft.append(iconImage) local yourIcon = Draft.getDraft('iconId'):getFrame(1) -- Or you can make it to be a table local icon = {} icon.FIRST_ICON = Draft.getDraft('iconId'):getFrame(1) icon.SECOND_ICON = Draft.getDraft('iconId'):getFrame(1) icon.ANOTHER_ICON = Draft.getDraft('iconId'):getFrame(1) -- To use GUI.createDialog{ icon = icon.FIRST_ICON }
Lua editor
-
MarioBitMap
- Villager
- Reactions:
- Posts: 15
- Joined: 31 Jul 2020, 20:54
- Location: Spain
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
I'll test it tomorrow, it's 4am lol. It makes sense I have to draft the json and get the image from there.
Thanks for the help and spending your time into this, hope you have a great day/night!

Thanks for the help and spending your time into this, hope you have a great day/night!
Code: Select all Reset
[ { "id":"MarioBitMap", "category":"Plugin_Creator", "skills":[{"skill":"Pixel_Artist"},{"skill":"Learning_C++_&_TTJson/Lua"}] } ]
JSON checker
-
MarioBitMap
- Villager
- Reactions:
- Posts: 15
- Joined: 31 Jul 2020, 20:54
- Location: Spain
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Draft .append(iconImage)
However, the forum's lua tester doesn't agree with the error given at the game with loading the lua file.
Looks like the game doesn't recognizes Draft functions.
When cut- pasting the code into a local function the error disappears, but the game isn't able to show the icon or open the menu it is linked to.
Code: Select all Reset
[ { "id":"MarioBitMap", "category":"Plugin_Creator", "skills":[{"skill":"Pixel_Artist"},{"skill":"Learning_C++_&_TTJson/Lua"}] } ]
JSON checker
-
ian`
- Metropolitan
- Reactions:
- Posts: 117
- Joined: 04 Apr 2020, 15:36
- Location: 日本
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Lua chatbox
Code: Select all Reset
Draft.append(woodIconJson) -- variable name aren't string, don't use quotation marks.
Lua editor
-
Hadestia
- Inhabitant of a Megalopolis
- Reactions:
- Posts: 721
- Joined: 17 Jul 2017, 14:16
- Location: Philippines
- Plugins: Showcase Store
-
Plugin Creator
Platform
Re: Lua chatbox
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 refreshLobby wrote: 23 Jun 2020, 15:24Code: 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
-
Lobby
- Inhabitant of a Supercluster
- Reactions:
- Posts: 3756
- Joined: 26 Oct 2008, 10:34
- Plugins: Showcase Store
Re: Lua chatbox
Nice comeback!
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
Lua editor
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'-
Hadestia
- Inhabitant of a Megalopolis
- Reactions:
- Posts: 721
- Joined: 17 Jul 2017, 14:16
- Location: Philippines
- Plugins: Showcase Store
-
Plugin Creator
Platform
Re: Lua chatbox
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
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
Lua editor
