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
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
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.
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)
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
Is there any way to load and image with lua and use it as an icon? I mean, can I assign an image to a variable wich will be shown when I use that variable in
... icon = Icon.EXAMPLE, ...
or are Icon.EXAMPLE a type of harcoded resource that can't be added by users?
Thanks in advance!
-- 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
}
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!
There's an error. It says attempt to call a nil value, at
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.
--This is a test for TT:TT plugin, (TheoTown Time Travel)
--Sill got to move part of this into a data type json object, not a menu.
local function showMenu(dialog)
local parent = GUI.get'$menuparent'
local d = Draft.getDraft('$res00')
--Will be woodcutter00 in a future.
local x = City.countBuildings(d)
local x2 = 1.15
local wood = math.floor(x2*x + 0.51)
local woodIconJson = [[
[
{
"id":"WCRIcon",
"type":"animation",
"frames":[{"bmp":"ancienticon.png"}]
}
]
]]
Draft.append('woodIconJson')
local iconWOOD = Draft.getDraft('WCRIcon'):getFrame(1)
GUI.createMenu{
source = parent,
actions = {
{icon = iconWOOD, text = "Houses: "..wood, onClick = function() 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 = IconWOOD,
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
-- 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
rjroldan1 wrote: 16 Oct 2020, 07: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):
@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
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