For documentation purposes. I will write it here.
Code: Select all
local number = 12
local character
local alphabet = {
"a", "b", "c", "d", "e", "f", "g", ...
}
for i = 1, #alphabet do
if number == i then
character = alphabet[i]
break
end
end
--> local character: string = l
Code: Select all
local number = 12
local character
if number == 1 then
character = "a"
elseif number == 2 then
character = "b"
elseif number == 3 then
character = "c"
elseif number == 4 then
...
Cityrjroldan1 wrote: 22 Jun 2020, 13:02 Ohh wait @Ølsken what's the role of "local number = 12" there based on my sent script?
Try this...
Code: Select all
"script":"../folderName/script.lua"
// 2 dots means you're leaving the folder, then enter to a new folder by its name, and will read the file
City.getRegionName() returns a string if the city is in a region and nil if not.rjroldan1 wrote: 23 Jun 2020, 02:54 Anyway how can i make Building only buildable when Region name returns true?
Code: Select all
if City.getRegionName() then
-- Passes if the city is in a region (any)
end
Code: Select all
{
"id": "$example_building",
"script": "my_script.lua",
...
}
Code: Select all
function script:event(x, y, level, event)
if event == Script.EVENT_PLACED and Tile.getBuildingDraft(x, y) == [draft] then
if not City.getRegionName() then
Builder.remove(x, y)
end
end
end
Code: Select all
if foo == nil or foo == false or foo == 0 then
-- Do something
end
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
I've wrote sort of function for that, it requires x and y of your building, ID of zone and radius. I tested it several times with different radiuses and it works greatDESOLAN wrote: 26 Jun 2020, 05:25 May i ask?
How can i build a zones with a radius of 5 from the example building (as the center of the zone radius)
Code: Select all
function buildZoneC(zeroX, zeroY, zoneId, radius)
zeroX = zeroX - radius
zeroY = zeroY - radius
local offset = 0
Builder.buildZone(Draft.getDraft(zoneId), zeroX + offset, zeroY)
for i=1, (radius * 2 + 1)^2 - 1 do
if i % (radius * 2 + 1) == 0 then
zeroY = zeroY + 1
offset = 0
else
offset = offset + 1
end
Builder.buildZone(Draft.getDraft(zoneId), zeroX + offset, zeroY)
end
end
Code: Select all
function script:event(zeroX, zeroY, level, event)
if event == Script.EVENT_PLACED and Tile.getBuildingDraft(zeroX, zeroY):getId() == "<id> then
buildZoneC(zeroX, zeroY, "$zonecommercial", 2)
end
end
Use TheoTown.registerCommand(string, function)Temgamer wrote: 26 Jun 2020, 20:49 How to set a console command with TheoTow.registerCommand()? I've tried putting it in script:init() and it doesn't work
Code: Select all
TheoTown.registerCommand("hello!", function()
local number = 11 + 1
return "Hello, the magic number is: "..number
end)
-- output: Hello, the magic number is: 12 [string]
Code: Select all
local function hello()
local number = 11 + 1
return "Hello, the magic number is: "..number
end
TheoTown.registerCommand("hello!", hello())
-- output: Hello, the magic number is 12 [string]
Code: Select all
local password = "something"
TheoTown.registerCommand("hello!", function()
if password == "olsken" then
local number = 11 + 1
return "Hello, the magic number is: "..number
end
end)
--- (console) "hello" > [nil]
--- password = olsken [string]
--- (console) "hello" > Hello, the magic number is: 12 [string]