#plugin-lua-and-fun

1 messages ยท Page 9 of 1

potent jolt
#

Like a sketch or something

random hamlet
#

I'll draw soon

#

But I am not really sure

#

So it will be better to just understand placing stuff

elfin geyser
#

How to use onInit function with GUIs?

potent jolt
#

that exists?

#

well if it does

#

you can do lua GUI.createDialog{ onInit = function() Debug.toast('initialized!') end }

#

I'm not sure what the point of this is though

#

As you can just run the code after creating it

elfin geyser
#

How to stored and retrieve 2 D array values from Theo/City Storage?

potent jolt
#
-- retrieve or create the 2d array
storage = Util.optStorage(TheoTown.getStorage(), '$pluginId', {})
storage.array = storage.array or {}
#

now you have to create the 2d part by inserting tables into the array

#

you can create rows by lua array[xvalue] = {} array[xvalue][yvalue] = value

#

im not sure this is a great idea though

#

maybe investigate vectors to see if they serve the purpose you want

elfin geyser
#

May i ask if i will come out retrieving the same table values from Resources to resources1 with these code?

#

Oh it seems like i forgot to use "k" What should i do for it?

weak mural
#

use Array:add(value, index) if you want to make it as array.

potent jolt
#

Resources and resources1 will be 2 tables with the same values in them

#

Since you don't insert with they keys they'll be ordered 0, 1 2 etc

#

The order might get messed up like that

potent jolt
#

Always forget that

#

I've probably had multiple bugs because of that

elfin geyser
#

I think this will work now

potent jolt
#

Why not use city name as the key?

elfin geyser
#

I will make a connection table with different user's city

elfin geyser
potent jolt
#

But yeah thisll work

#

True

#

You'd have to update it on city exit

#

Or somewhere else

elfin geyser
#

Still clueless but on my thought , if user change the city name it will store again on that and if matches any key I'll make a function to remove the old values

weak mural
#

use city id

potent jolt
#

Oh that's why Ive never heard of that function before

light plinth
#

used for pseudo-randomness

potent jolt
#

Well in this case that's exactly what's neede isn't it

light plinth
#

probably

#

didin't read above

open arch
#

what are those for?

random hamlet
#

template is some premade parameters I guess

#

and I don't know about texture

#

but may be hill texture

open arch
#

oh okay

random hamlet
#

funky

#

these chinese names are good

#

because

#

for me they don't make sense just like real chinese names

#

I spent too much time on this.... but at least it's more advanced than stacking random letters

potent jolt
#

you can have some preset values

#

and put them in many drafts using templates

open arch
#

I think I wont need those

random hamlet
#

erksmit rate my ultra realistic chinese names @potent jolt

#

generation result but all of them are based on Azpilicuetagaraycosaroyarenberecolarrea

open arch
#

@potent jolt wants edge frames but there arent edge frames on the game codes tho

potent jolt
#

ยฏ_(ใƒ„)_/ยฏ

light plinth
#

edge frames are defined by the template

elfin geyser
#

Can anybody would like to help me about formula

open arch
#

Krabby patty formula? No way

random hamlet
elfin geyser
#

Nvm btw what's the lua version of theotown has? i need 5.3 to use floor division

weak mural
#

math formula? lol

elfin geyser
#

Does these will work?

 local v = v//50
open arch
#

@elfin geyser

#

I think it is not 5.3

elfin geyser
#

Sad

potent jolt
#

The heck is floor division

#

Looked it up

#

Why not just divide then floor

weak mural
#

print(math.floor(5/2))

light plinth
#

genius

open arch
elfin geyser
#

What's the Gui id of these two?

weak mural
#

no id

potent jolt
#

Maybe Yusuf knows from his old ui project

#

@open arch

open arch
#

I never worked on ui tho

#

I was planning to use drawings instead of ui

elfin geyser
#

Ohh since it doesn't have id how can i get if user uses right sidebar tool?

light plinth
#

probably by using GUI:getRoot and getChildren, etc ...

elfin geyser
#

No i mean is there any boolean function to check whether user checked the right sidebar tool from settings

potent jolt
#

Ah

#

Check the settings table

#

It should contain all settings

random hamlet
#

iei

#

@elfin geyser so you use dialogs to show GUI elements?

elfin geyser
#

Have you tried experimenting with lobby's GUI tool?

random hamlet
#

No

#

What's that?

elfin geyser
#

It's open source in the forum

#

Its a example of stuff you can possibly make

random hamlet
#

Oh

#

GUI example?

#

I've seen it

elfin geyser
#

Go to lua scripting it's well explained that there

random hamlet
#

I wanted to get GUI like this

#

It's better to know how to compose GUI though

#

Erksmit suggested to use dialogs and that seemed nice

#

But you need to create templates

#

Erksmit gave me a layout but I'm dumb and I decided to figure it out soon

#

I wish I could just use coordinates

#

I thought you used something else for GUI, that's why I was so curious

elfin geyser
#
local function panel()
 local dialog = GUI.createDialog{
   width = 180,
    height = 200,
    icon = Icon.OK,
    title = 'TITLE',
    pause = true,
    onInit = function() end,
    onClose = function() end
   }
 local layout = dialog.content:addLayout{vertical = true, spacing = 2}
local theme = dialog.content:addCanvas{
onDraw=function(self,x,y,w,h)
Drawing.setAlpha(1.0)
Drawing.setColor(145, 129, 116)
Drawing.drawNinePatch(NinePatch.PANEL,x,y,w,h)
  Drawing.reset()
  end
}
local function addText(txt,height)
local line = layout:addLayout{height = height}
line:addLabel{text = txt, w = 60}
return line:addLayout{ x = 62}
end
local txt = addText('test',-30)
local btn = addText('',-30)
btn:getFirstPart():addButton{
icon = Icon.Ok,
text='i am a button',
w = 30,onClick= function() end
}
btn:getLastPart():addButton{
icon = Icon.Ok,
text = 'button also',
w = 30
}
end

Try not the exact you wanted but i hope you figure it out

random hamlet
#

Okay thanks I'll try

open arch
#

A lamplighter is a person employed to light and maintain candle or, later, gas street lights. Very few exist today as most gas street lighting has long been replaced by electric lamps. Their services were no longer required in 1899, when electrical systems were installed in the US.

#

what about this

elfin geyser
#

Already has

open arch
#

o

#

wow

#

how does it work

elfin geyser
#

Still don't have night anims yet

#

Oh i mean the lamp

open arch
#

I mean like this; soo there is a lamplighter house and it spawn people in black suits once it is near night time. They pass lights and light them up once they reach them

elfin geyser
#

hmmm gonna seek if there's a function what car id pass on that tile

random hamlet
#

Btw

#

I remember there were car related functions

#

How do they work?

#

I'm thinking of using them soon and Yusuf had some hard time with them

open arch
#

but are your light fences?

elfin geyser
#

I just stole this

open arch
#

lol

#

it wasnt working

#

wait

#

did you get it from here

elfin geyser
#

Yes

#

And stole caused im really curious how to use City.spawnCar() function

open arch
#

I think I asked you guys about it too

#

but nobody knew because they didn't experienced it

#

also asked ja how he did rocket supply thing but he didnt respond, or I am remembering wrong

elfin geyser
#

There's a something called City.carReach? Something like that dunno

open arch
#

there is target reached

#

but it is not a script

#

it was an event afaik

elfin geyser
#

i think in spawnCar() you should put the neighborhood tile of the building where it would spawn?

open arch
#

I am kinda remembering I tried that too

#

I also tried it with adding car spawner to json and without it but I am bad at lua soo it is better if you test them

elfin geyser
#

I'll try now

random hamlet
#

Well car scripts are hard I guess

open arch
#

maybe

#

and maybe not, because not many experienced it

weak mural
#

not hard, just difficult

open arch
#

@weak mural you tried it?

weak mural
#

almost all functions. lol

elfin geyser
#

I think this gonna be need than using City.getBuilding()

open arch
#

btw is ian bearbear on forum?

open arch
weak mural
open arch
#

bearbear was working on a medieval plugin

#

really back then

elfin geyser
#

I never heard about him anymore

open arch
#

same

light plinth
#

became a Gentoo user

stoic vector
#

sad that bearbear isn't active anymore

open arch
#

wow

#

how

elfin geyser
#

Just analyze the spawn() function

open arch
#

so

#

it spawns them daily

#

but

#

you put the building's x y and not the road's x y

#

is that true? I kinda forgot lua

elfin geyser
#

Yes

open arch
#

but why it didnt work for me tho

#

๐Ÿ˜”

#

oh you used city spawn car different and not like me

elfin geyser
#

I think it's a bug to store the draft in variables than calling it directly inside the parameters

open arch
#

so you say I should have get the drafts inside the scripts?

elfin geyser
#

My script isn't not in anybuilding type on in type:script

open arch
#

but it is nice to see city spawn car working

#

can you now try target reached?

random hamlet
#

Oh

#

So car spawn function takes road cords?

open arch
#

no

brazen sluice
#

no

open arch
#

it needs building

random hamlet
#

Thank god

open arch
#

roads might be dumb actually

random hamlet
#

It would be painful

open arch
#

yep

brazen sluice
#

dumb road

random hamlet
#

I want to make something more complex and gameplay related in theotown

#

Like something industrial

#

Or solar swarm idea I mentioned

random hamlet
#

Btw Yusuf

#

Are you going to finish complex industri?

open arch
#

I started the industrial revolution on theotown

open arch
random hamlet
#

Okaay

#

Wait

#

Do you need a car spawner to use car related functions?

hybrid knot
#

?

weak mural
random hamlet
#

Hope it's not necessary

#

Because it's weird to have car spawner in building if it's going to use Lua car functions anyway

weak mural
#

maybe for a truck or something that can take or drop some stuff to another building.

open arch
#

steel mill ๐Ÿ˜”

elfin geyser
#

I made a function for you, remember that here in my code, it depends on spawner count how car reach its targeted building

local targetCoordinates = {}
local spawnCoordinates = {}

local function collectLocation()
 local targetX,targetY,spawnX,spawnY
 if City.countBuildings(Draft.getDraft(targetDRAFT)) then
   for i=1, City.countBuildings(targetDRAFT) do
     targetX,targetY = City.getBuilding(i,Draft.getDraft(targetDRAFT))
     targetCoordinates[i] = {x = targetX, y = targetY}
   end
 end
 
 if City.countBuildings(Draft.getDraft(spawnDRAFT)) then
   for i=1, City.countBuildings(Draft.getDraft(targetDRAFT)) do
     spawnX,spawnY = City.getBuilding(i,Draft.getDraft(spawnDRAFT))
     spawnCoordinates[i] = {x = spawnX, y = spawnY}
   end
 end
end

local function spawnCar(targetTable,spawnTable)
   for i = 1, #spawnTable do
     City.spawnCar(Draft.getDraft(carDRAFT),spawnTable[i].x,spawnTable[i].y,targetTable[i].x,targetTable[i].y)
   end
end
 
function script:nextMonth()
  collectLocation()
  spawnCar(targetCoordinates,spawnCoordinates)
end
weak mural
#
local stuffOnFirstBuilding = 10
local stuffOnSecondBuilding = 0
local truckCapacity = 5

function script:event(_,_,_,event)
  if event == Script.EVENT_CAR_SPAWNED then
    stuffOnFirstBuilding = stuffOnFirstBuilding - truckCapacity
  elseif event == Script.EVENT_CAR_REACHED then
    stuffOnSecondBuilding = stuffOnSecondBuilding + truckCapacity
  end
end
elfin geyser
#

This code should be clipped on building drafts i guess

weak mural
#

you can make global variables or use require function.

#

or use the storage.

elfin geyser
#

I don't know if global variables are accurate since it can be duplicate by other script with the same variable naming

weak mural
#

city storage or building storage.

elfin geyser
#

@weak mural have you tried lua with data base?

random hamlet
#

You need to put it in building code or...?

#

Sorry if being very dumb

weak mural
weak mural
random hamlet
#

Oh okay

#

I thought when using car code like that, you usually use car spawning script too

weak mural
#

actually, not yet. lol

open arch
#

ian

#

what you working atm

#

not talkin bout just TT stuff

elfin geyser
#

Gonna ask, does other script can access and retrieve values from plugin storage using their draft in Util.optStorage(TheoTown.getStorage(), [target draft to retrieve values there])?

potent jolt
#

Yes

#

Storage is shared between plugins

#

That's why we usually use the id for the storage key

elfin geyser
#
--Script 1

function save()
stg = TheoStorage()
stg.var = 60
end

--Script 2
function storage()
return  Util.optStorage(TheoTown.getStorage(), 'Script-1-DraftID')
end

function save()
stg = storage()
stg.var = 90
end

Do they work like this?

potent jolt
#

If they share the same id for getting storage the values will be shared

#

I've used it for my camera plugin

elfin geyser
#

The values can also be change depending on how other script declared it?

potent jolt
#

Yes

#

Whether 60 or 90 will be saved is dependent on which script ran last

#

Which is kinda arbitrary and can't be ensured

elfin geyser
#

I need to use this just to transfer and trigger events

potent jolt
#

thats a good application for it

elfin geyser
#

Thanks for the respond, really helpful

#

Ah one more thing does ** Draft.getDrafts()** also return drafts of GUI's?

potent jolt
#

gui objects arent drafts

#

so no

#

unless theres some gui type im unaware of

cerulean crypt
random hamlet
#

@open arch yo I think that's yours plugin

#

wait why zones+ is in cemetery

open arch
#

its been years

#

wth is this

cerulean crypt
#

[
{
"id": "$city_cemetery_zones+",
"type": "zone",
"frames": [
{
"bmp": "city_factory_tile.png"
}
],
"width": 1,
"height": 1,
"author": "Cerrera",
"placeable": true,
"base": "$zoneindustrial",
"rci": true,
"price": 100,
"needs road": false,
"category": "$cat_zone00",
"separator": false,
"ordinal": 7,
"draw ground": true,
"title": "City Factories",
"text": "Ever wanted a clean industry area? There it is... It just makes noise and it will fit your city sides. There isn't any smoking factories in this zone",
"preview frames": [
{
"bmp": "city_factory_icon.png"
}
]
},
{
"id":"$deco_city_factories_zones+",
"type":"body disposal",
"influence body disposal":200,
"auto build":true,
"need road":false,
"influence park":100,
"provide aspect body disposal":10,
"privileged":"lol",
"price":0,
"monthly price":0,
"build time":0,
"performance":true,
"width":1,
"height":1,
"frames":[
{"x":1536,"y":48,"w":32,"h":16,"count":3},
{"x":1696,"y":96,"w":32,"h":16},
{"x":2016,"y":48,"w":32,"h":16},
{"x":1632,"y":144,"w":32,"h":16,"count":2},
{"x":1760,"y":160,"w":32,"h":16,"count":2},
{"x":1728,"y":240,"w":32,"h":16},
{"x":1920,"y":224,"w":32,"h":16},
{"x":1536,"y":512,"w":32,"h":16,"count":3},
{"x":1824,"y":512,"w":32,"h":16},
{"x":1856,"y":608,"w":32,"h":16},
{"x":768,"y":0,"w":32,"h":16,"count":3,"offset x":1024},
{"x":768,"y":16,"w":32,"h":21,"count":2,"offset x":1024},
{"x":512,"y":256,"w":32,"h":16,"count":2,"offset x":1024}
],
"meta":{
"tags":{
"body disposal":{
"zones":["$city_cemetery_zones+"]
}
}
}
}
]

open arch
#

is this my code?

#

I never used cemetry stuff

cerulean crypt
#

Experiment

open arch
#

yeah

cerulean crypt
#

I just want to make cemetery zones

open arch
#

this isnt the right plugin to use codes for it

#

imo

#

you should look up kingtut's garbage zone plugin

#

zones+ is an rci zone plugin

cerulean crypt
#

Thanks

open arch
#

no problem

potent jolt
#

is there any way i can draw text colored

#

like this

light plinth
potent jolt
#

so ill have to use a canvas and draw text on that instead of just adding a label

#

well whatever works

slate oxide
#

Hello everyone. I'm making a decoration for the road. I found the code on the forum, but I do not understand what is responsible for what. There is an animation item here. Is there any animation in the decorations?

#

{"id":"$anim_roaddeco_sample00_00","type":"animation","frames":[{"bmp":"frames.png","x":0,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_01","type":"animation","frames":[{"bmp":"frames.png","x":32,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_02","type":"animation","frames":[{"bmp":"frames.png","x":64,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_03","type":"animation","frames":[{"bmp":"frames.png","x":96,"w":32,"handle y":8}]}

random hamlet
#

ot creates animation

#

animation draft*

#

to use later

#

I guess

slate oxide
#

do I need to leave this part of the code?

#

save

#

or its np if i delete

potent jolt
#

depends if you use the animation or not

#

if not its safe to remove

random hamlet
#

I guess he is making a road deco

#

in that case

#

I think it's necessary

open arch
#

How to add timers?

#

Easy way

potent jolt
#

use Runtime.postpone

#

to run a function at a later time

#

you can basically call those endlessly without too much consequence

open arch
#

Hm

#

Thanks

open arch
#

I think there isnt a timer code or something ๐Ÿ˜” why coding things like that

#

Also we need tables to save the latest ms value, right?

random hamlet
#

If that makes you happier

open arch
#

Why do we need to calculate miliseconds ๐Ÿ˜”

potent jolt
#

Just multiply by 1000

open arch
#

So 5 seconds 5000 and I want to have like 10 minutes. Thats 10x60x1000?

#

And it is a big number, I am wondering if we can store postpone numbers

potent jolt
#

Correct

#

Why 10 minutes though

#

That's quite a long time

open arch
#

hm

potent jolt
#

A player might not even sit in his city that long

open arch
#

Aa

potent jolt
#

For long durations

#

You should track the durations yourself so you can save them when the player exits the city

open arch
#

But if we have a store system for i- nevermind you are true

potent jolt
#

You can use runtime.gettime to accurately tell the passed time

#

Or os.time if you want less accurate

open arch
#

Things getting more complicated. I think like what you said will use postpone with small values or daily functions

#

No need to store anything and make things harder for a small thing like this

potent jolt
#

Daily sounds like something for script:daily

#

You want your things to depend on in game time no?

open arch
#

Yeah in game time

#

Daily seems soo limiting tho, I want every thing to have their own times, soo it will allow creativity and combinations

potent jolt
#

The downside of postpone is that you have no control after running it

#

For exmaple

#

If you run it and the user exits the city

#

The function Will still get ran

open arch
#

Huh

potent jolt
#

And if the user quits

#

The function won't ever be ran

open arch
#

I expected the quit, function stop and reset but didnt know it continues if player leaves city

#

Cant we make this function to get connected to city enter exit functions?

#

I dont really know how to make two functions interact with each other tho, dont even know if it is possible

potent jolt
#

Postpone works everywhere

#

You have to keep track of what's changed

#

Like

#

If you have a big postpone

#

A user could switch cities

open arch
#

And it will continue in his other city

potent jolt
#

You'll have to check whether it's all correct when the function runs

open arch
#

Isnt there an easy way for timers?

#

a line that works in city enter function and works literally timer

potent jolt
#

Not until you invent it

open arch
#

Oh

#

Local functions?

potent jolt
#

Well duh

open arch
#

๐Ÿ˜”

potent jolt
#

You best be using those regarless

#

For organisation

open arch
#

Thats true

#

Well I think postpone only needs to know if it is in a city or not

#

This is what I understand

potent jolt
#

You can make a function to check that

#

Well

#

You also have to check if it's the same city

#

Using city id

open arch
#

Why

#

Wait

open arch
potent jolt
#

Postpone does not reset

open arch
#

Ah shi

potent jolt
#

Postpone runs a function after a set amount of time

#

Regarless of what happens in the meantime

#

Unless the game exits

open arch
#

What a cruel function

potent jolt
#

The rest is up to you

#

Not really cruel

#

It's generic

#

Useful for everything

#

But needs work to work for a specific application

#

If it was city only I'd complain about it for my plugin that needs it outside cities

open arch
#

Talking about city id, it will just look if it is a different city right? Then there is this problem. Player exits city and waits at region menu, script continues and player enters the same city. Is this a problem?

potent jolt
#

Basically

#

You give the function the current city id

#

Then when the function eventually runs

#

You compare it to the new city id

#

If they match it's the same city

#

If not it's a different one

#

You should do that after checking if you're in a city in the first place

open arch
#

Okay thanks for help

#

Also do you know who are adding those lua codes, Is it only lobby?

#

Because with a little hope I will still suggest timers

potent jolt
#

Idk

#

Just go through psuggest

open arch
#

Probably wont happen since there is a "possible way" of doing it

potent jolt
#

Likely yes

#

Since your suggestions is fairly use specific

random hamlet
#

@open arch what do you want to do with timer?

#

Tell me context in DMS, please

#

Maybe there is another solution...

potent jolt
#

Or in le server

random hamlet
#

Yes

open arch
#

Well

#

Didnt we talked about this earlier

potent jolt
#

I didn't read

#

Can go back

open arch
#

Read steelmill plan on the server

potent jolt
#

Why not convert a certain number of materials per day

open arch
#

Soo like a material comes out after three days instead daily?

open arch
potent jolt
#

Well I'm just looking at cities skylines

open arch
#

Soo steel; 16 coke, 8 iron and 4 limestone. Coke oven creates 6 carts a day, iron port creates 8 trucks a day and limestone port creates 6 etc etc

potent jolt
#

Where the industries have fairly high volumes of products

#

You should probably have ratios though

open arch
#

yeah, thats what I tried to say

#

Balancing such thing like this is hard

#

I think I will talk with danek too if he has an idea

open arch
#

@random hamlet

random hamlet
#

my CAS was playing sounds without cords, idk

#

but I think it won't work with several buildings

#

otherwise it's probably fine

#

try it

#

wait it's on entercity

open arch
#

I already added a max amount for sealand, player cant build more than 1

#

yep

random hamlet
#

weird way of fixing sound

#

but ok

open arch
random hamlet
#

is the sound looped?

#

and how long is the sound?

open arch
random hamlet
#

ik I'm joking

#

but I think the sound will play when you enter the city and then end

#

and all

open arch
#

there is a loop for it

#

oh I thought it was default true

#

experimenting sounds for factory

elfin geyser
#

AoS doesn't have any sound FX : (

open arch
#

@elfin geyser find 3 or 4 seconds loop medieval sounds from freesounds websites

elfin geyser
#

Gonna try at the last phase before releasing

open arch
#

I am wasting my hours trying to make 4 seconds of sound on my potato pc, this is hella super slow. Pain

potent jolt
#

You can add some script to your buildings to play them occasionally

open arch
#

soo several 4sn sound clips that plays randomly?

potent jolt
#

I gues

#

As long as it's subtle

#

Unlike some other noise making plugin I have

#

Looking at ja's party house

open arch
#

same

#

does it work well on mobile?

potent jolt
#

Works just fine

#

But that's just 1 house

#

I can't say for like 30 factories

#

Maybe it's a bad idea

#

And just use custom on click noises

open arch
#

I am going to put a radio effect on sealand, it is also 1 time build but thought could use playsound with really low volume on factory components. Since they are factory components I can just put a really small loop of a sound

potent jolt
#

Idk what'll happen when you build say

#

2 clusters of factories on 2 seperate districts

#

Would the sound overlap?

#

It'd probably clip like crazy

open arch
#

sounds will be fitable to overlapping

potent jolt
#

And you can't have 1 sound playing instance either

open arch
#

I dont think overlap for factory sounds is bad, this is what exactly happens tho isnt it

potent jolt
#

We'll know when we get there

open arch
#

true

#

I have some sounds of rolling houses recorded in my local area

#

also tried to give it an effect like it is sounds is how it gonna sound at aerial

#

I cant find it ๐Ÿ˜” nevermind I think I will make it again

open arch
#

@potent jolt are you avaiable?

#

only play sound isnt working

elfin geyser
#

Are modules need also to have draft?

Also can I store values to either TheoTown/City storage on modules?

random hamlet
#

@open arch 1 sec

#

not exactly your case

#

but as example this is the sound code in CAS

open arch
#

@random hamlet can we work with city.sound ?

random hamlet
#

I mean

#

idk I don't have experience

#

but in CAS it plays sound everywhere

open arch
#

I will give you the file

random hamlet
#

file of what?

open arch
#

whole thing

elfin geyser
#

Need help here

potent jolt
#

It's better not to use require

#

At it does not work with luawrapper

#

And no, you cant use hook into script functions within modules

#

You could make a seperate script draft and add functions to that

elfin geyser
#

The is just a test I don't know why it can't find my module

potent jolt
#

Because theotowns implementation is not pure lua

elfin geyser
potent jolt
#

You retrieve the script attached to the draft

#

Then you can run its functions

#

That are not defined local

elfin geyser
#

Any theo API to retrieve that?

elfin geyser
#

**Draft.getDraft("otherDraftID"):getScripts() ** right?

potent jolt
#

yes

#

thatll return an array of attached drafts

brazen sluice
#

Free tunnels
Free tunnels
Free tunnels

potent jolt
#

and then just grab the 1st

potent jolt
#

dont we have that

brazen sluice
#

We have, but not with Simon's plugin

potent jolt
#

doesnt sound like a me problem

open arch
#

sir this is not plugin discusisson

elfin geyser
#

Does this works with luaWrapper?

brazen sluice
potent jolt
# open arch

did you put a toast after to ensure it actually ran

open arch
#

yes

brazen sluice
#

yes

open arch
#

I put toast at both entercity and update

#

entercity didnt work

brazen sluice
#

I have no idea what this channel is about. Is this drugs?

open arch
#

I guess

potent jolt
#

so it errored

open arch
#

there wasnt errors only city play sound wasnt working otherwise toast was showing sound draft id, building id and x,y

#

in script update

potent jolt
#

okl

#

but did you toast after playsound

#

to ensure the function didnt error

open arch
#

I did copy past the same toast from update to city enter, it didnt show anything

potent jolt
#

lemme pull up uh

#

the epic plugin

open arch
#

the troll plugin

potent jolt
#

City.playSound(songDraft, bx, by, 0.5, true)

#

checks out

open arch
potent jolt
#

have you ensured all your variables are initialized?

open arch
#

wait my computer is lagging

#

what does that mean, I tried to open a new chrome tab for translate

elfin geyser
#

@potent jolt I could still get the return values with this right, when using **: getScripts() **?

open arch
elfin geyser
#

Gonna ask later

elfin geyser
# potent jolt probably

I tried

local AOS

function script:init() 
  AOS = Draft.getDraft(id):getScripts()  
end

And use its function

AOS.getRank() 

but it says it's null

potent jolt
#

Get scripts returns an array of scripts

#

You have to get the 1st script first

weak mural
#

require is only need a lua script. you don't need to make a draft. but, you will have some problems without luawrapper.

elfin geyser
potent jolt
#

It still returns an array of all scripts

#

Even if there is only 1 script

#

It is wrapped in an array

#

First you get the script itself

#

From the array of scripts you got off getscripts

#

Then run the function

weak mural
# open arch

place playSound on update and x, y on the event script or something to prevent lagging.

open arch
open arch
#

I forgor to do this ๐Ÿ’€

random hamlet
#

he forgor

open arch
#

@SauerKraut

#

@light plinth bruh

#

nvm

light plinth
#

?

potent jolt
#

Only the neccesities

stoic vector
#

how to store variables value after exiting a city?

light plinth
#

either transition variables or city/global table if you want persistence

stoic vector
#

where i can read about city table?

light plinth
#

docs

stoic vector
#

what does it mean 'no guarantee'?

#

like if the game crashes the method won't be called?

light plinth
#

or android kills the app, yes

potent jolt
#

You should probably save it on city:save

stoic vector
#

i have an issue.
i have a script which is called from such a json

    "id":"$wood_industri_lua",
    "type":"data",
    "script":"wood.lua"
}]```
and `function script:daily(_, _, _)` doesn't work there. i tried to replace it with such code:
```-- checks for a day change
local day = City.getDay()
if day ~= current_day then
  daily()
  current_day = day
end```
but instead it is called every frame, despite that the same code for months works correctly
#

what is the cause of that problem?

open arch
#

in factory server

potent jolt
#

I did not say that

#

Did you read the documentation?

#

Will be called on a daily basis for every building or road that are instances of the owning draft.

#

This clearly says it'll be called for buildings

#

Which your script isnt

#

You should use script:nextDay

#

Please read the documentation carefully before labelling something as broken

stoic vector
#

oh gosh....

#

ok thank you

stoic vector
#

how to display pop-up message with lua?

#

ok nevermind i found it

golden umbra
#

For anyone wanting to apply for plugin, contributor (Builder) and influencer roles, please PM Pidroid on forums with your role request.
URL to compose a PM: https://forum.theotown.com/ucp.php?i=pm&mode=compose&u=10911
Additionally, please provide your discord username and user ID (snowflake).

You may also provide additional information which may make you more eligible for the role, such as your contributions for the game, etc.

#

Oke.

elfin geyser
elfin geyser
#

Why there's a limit number of variables in a script?

light plinth
#

There's a what?

#

what makes you believe you did?

potent jolt
#

What'd you do to reach that

elfin geyser
#

It toast a runtime wrapper error, of line number used more than 200 local variables

potent jolt
#

youre probably gonna have to rethink your scripts structure

#

likely divide it up into multiple smaller scripts

elfin geyser
#

I guess it's fine for now gonna add more scripts for updates

potent jolt
#

why does this only get called for buildings and road drafts

open arch
#

soo you make your own pre-build builds using it and it saves those in a special category

#

I am not sure if lua can create its own json files

weak mural
#

so you want to build a composition without build the buildings?

#

lua can, but you need to restart the game to load the draft.

open arch
#

yes

open arch
weak mural
#

yeah, it's possible. but you can't share it as a plugin, only for the city on one device.

open arch
#

wdym

weak mural
#

if you want to copy an area and save it into the composition, that's only can be used for all cities on one device.

it's like you want to the same area in many cities.

open arch
#

yeah

#

I think it is fine

weak mural
#

if you want to share the composition with other people, you need to build a composition draft manually.

open arch
#

thats true

#

hm

#

but if it already creates its own jsons for compositions, we could just hand the json file to other user but hmm

#

he has to use same plugins

#

btw, like your hill and select tool, you can make it a online useable plugin. Soo people can take compositions of other players builds

weak mural
#

i think it will be simplest to share the composition if you use the composition tool and make it into a draft. but, if you want to use it for personal only, i can make the tool and store the id and the positions.

#

so you can build the same area in many cities.

open arch
#

wait, isnt that tool already in plugin creator tool by lobby tho?

#

I mean it would be nice if it creates composition automatically

weak mural
#

it will be loaded automatically after restart. you don't need to create a draft again like pct.

weak mural
#

premium buildings can't be used in a composition. bear_shrug

misty python
#

i mean

#

of course

pale ember
#

Can i use a own picture as icon for buttons?

elfin geyser
pale ember
potent jolt
#

You can get the frame from a draft and use it as an icon

pale ember
#

[I have no idea what a draft is xD] -edit : I don't know to create one with a frame

potent jolt
#

Draft is basically a building

#

Or a category

#

The JSON you write gets turned into a draft when the game loads it

elfin geyser
pale ember
#

So i create one and how i can use it as an icon ?

elfin geyser
#

Using Draft.getDraft([[string id of the draft]]):getFrame(1) -- gets the first frame

You can store it on a variable or directly on GUI

#

Why the game doesn't support File/IO :(

weak mural
#

loadImage or loadPng function is enough to be added.

potent jolt
#

Sounds like it would break the assumption that loaded textures never change

pale ember
#

How can i create a automatic framechage if its winter?

potent jolt
#

theres a winter frames tag for that

pale ember
#

And how can i trigger the frame with the tag?

potent jolt
#

happens automatically

pale ember
#

I found it but my wifi bugs ... Thanks anyways

dark kernel
#

How to script the game

#

Anyone add and help me

torpid spear
elfin geyser
#

What will happen on values on plugins script that used city storage and used them online

open arch
#

iirc thats impossible isnt it

potent jolt
#

Let's find out

#

And I'm also curious myself

#

@light plinth is city storage table stored in the .city or not

#

If I transfer a .city file to another device, will it keep the city storage

left kernel
#

How do i add my building a monthly price ๐Ÿ˜ค

light plinth
#

yes

open arch
#

o.o

potent jolt
open arch
#

Hmm

#

What about complex industri online trading too?

potent jolt
#

We would need networking

#

I highly doubt we will get that

open arch
#

What about- oh nvm

#

Nevermind it is too open to cheating possibilities

potent jolt
#

i dont think thats too big a problem

#

its more of a security thing

#

and whos actually gonna use it

open arch
#

Yea

#

Only us if we ever play on a region with it

dull temple
regal falcon
#

Is there anything wrong with this?

noble widget
#

you're missing a comma after "people": 174

#

I think, the indentation is all over the place ๐Ÿ˜›

regal falcon
#

What you mean by indentation?

noble widget
#

lines 17, 18, 19 are not indented properly, but it should still work

#

it's probably just the missing comma at the end of line 16

regal falcon
#

I did that
But for whatever reason
The game keeps deleting the animations bit

hybrid knot
#

Is there a script that could like Spond a bunch of cars like create a huge traffic jam along the highway

#

?

#

A highway*

noble widget
#

wild guess, but should it be "animations" instead of "animation"? since it's an array

south garnet
noble widget
#

but that's what I said ๐Ÿ˜ฆ

south garnet
#

Oh

regal falcon
#

Itโ€ฆ
Finallyโ€ฆ
Works!

#

Tysm!

noble widget
#

๐ŸŽ‰

left kernel
#

When i place my decoration there is a water under it how do i fix it

trim remnant
#

draw ground: true

#

I thinl

left kernel
#

Oh okay ill try it later

elfin geyser
potent jolt
#

Yes

#

Nor their contents

elfin geyser
elfin geyser
#

If i put script:init() on a module it will execute by the script uses that module actually without calling that function?

potent jolt
#

no

#

i wouldnt bother using modules

#

its more pain than its worth

full topaz
#

How to create a plugin manifest file for bundled plugins

potent jolt
#

put manifest in plugin folder

#

profit

#

just put it in the top level folder

full topaz
#

ok thanks i will try

#

I wish I could enjoy all those plugins (placed in folders) in the online region

vagrant flume
#

@everyone Give me json code for train or car please:)))

misty python
#

@vagrant flume please do not attempt to ping everyone

#

besides, you can look in the forums

#

and this channel is for plugin fun and lua

random hamlet
#

No we won't give you codes vexayse you wanted to ping everyone

potent jolt
#

there are plenty of examples on the forum

random hamlet
#

Shhh

left kernel
#

I wanna learnnlua scripting i still dont understand it hehe

random hamlet
#

Ok

stoic vector
random hamlet
#

Uh idk

elfin geyser
#

How to set state for "task"(settings) using lua?

light plinth
#

task settings?

elfin geyser
#

Yes

#

The task from ingame settings

#

Idk if its under "Gameplay"

light plinth
#

Removed feature, seems like the setting was forgotten to be removed

elfin geyser
#

Why

light plinth
#

Because we forgot to remove it

elfin geyser
#

It may remove soon?

light plinth
#

That setting will be removed, yes

elfin geyser
#

No way

#

Task is associated with city notifications for building stuff, and its annoying

light plinth
#

That's not what the setting is for

elfin geyser
#

What does it for?

light plinth
#

It used to be for a feature which to sum up;

Various TheoTown in-game characters would give you tasks for which completion you'd get various rewards.

elfin geyser
#

Just like wanting us to declare zones? That's likely what i mean

light plinth
#

Build a school for the children

#

Rewards XP, money or diamonds

elfin geyser
#

Speaking of Xp, setXP will actually do nothing, Game keeps on resetting the xp you had before when opening the rank tab

light plinth
#

Shouldn't be the case, it works for me.

weak mural
#

me too

light plinth
#

Akso

#

Can you elaborate on influence allocation for plugins?

elfin geyser
#

It's like how to allocate custom road flags

light plinth
#

But what's the purpose

elfin geyser
#

Visible custom influence

light plinth
#

Yeah, but the purpose?

elfin geyser
#

Actually nothing, but im done making my defenses with radius range, so i was hoping i can make those range visible if player able to see 'em, just like how visible influence works

torpid spear
#

it might be useful with some lua functions

elfin geyser
light plinth
#

In either case

#

The current influence system would need a refactor

potent jolt
#

range sounds more like a thing youll have to make yourself

#

since its just within range or without with no gradient

minor quartz
#

gays how many of plugin enough to make a game with eany crashes

stoic vector
minor quartz
#

@stoic vector ok marco i will do that

uncut field
misty python
elfin geyser
#

One more thing, can i use Fun var set from lua to used as state for Fun functionality variables?

light plinth
#

Fun variables can only store integers, make of that statement what you will

misty python
#

fun doesn't sound that fun to be fair

potent jolt
#

It's just like Celeste wavedashing

#

Fun scripting is "fun"

misty python
#

"fun", of course, is in rainbow text

elfin geyser
#

What i mean is fun from lua to fun on json

potent jolt
#

should be possible

elfin geyser
#

What are these attributes does?

light plinth
#

which

elfin geyser
#

Mute and mute lua?

light plinth
#

Mute does nothing

#

Mute lua prevents Lua from logging any errors anywhere

potent jolt
#

So if I did that you wouldn't even notice I get an error every frame

light plinth
#

We would

#

It gets logged to ASS runtime logs

potent jolt
#

Haha ass

potent jolt
#

Can't blame me for that

#

Besides

#

I am aware of how bad of an idea having errors occur regularly is

light plinth
#

If we logged what ASS logs

#

You'd crash the moment you start the game

elfin geyser
#

My phone gets lags if there's an error on my script

potent jolt
#

Lol

#

But yeah error bad

#

Clearly this is why c is better

#

No slowdown on error

elfin geyser
#

Yeah that was my bases for determining errors

#

Specially script doesn't use of lua wrapper

light plinth
potent jolt
#

If you cant use luawrapper

#

Try using strict lua

potent jolt
elfin geyser
potent jolt
#

Yes

#

It makes the game crash if you get a lua error

#

So a decent alternative to luawrapper

elfin geyser
#

But not readable error?

#

I mean like what luawrapper does

potent jolt
#

I haven't actually gotten any errors with it

#

But pretty sure it works the same as other crashes

#

Think you'll get the line number and stuff

elfin geyser
#

Alright thanks

weak mural
elfin geyser
#

Just theory, Do i need other script to re-enable script that used this?

#

Also, based on my experience i concluded that strict lua can also detect errors on custom modules unlike luawrapper

potent jolt
#

Or is this an edge case where you use runtime.postpone to reactivate?

#

Or some similar method

chrome ginkgo
#

I'm going to release a new industrial plugin. I looked but I couldn't find the code to change the images with smoke animation and the number of workers. Could someone give me the json tip?

#

I would like to include night mode also in my plugins from now on. If anyone can pass a code example thank you

random hamlet
#

@chrome ginkgo it's not scripting

#

Btw number of workers is "people":number

#

Or something

#

Don't remember the smoke

#

Check on forum

chrome ginkgo
stoic vector
elfin geyser
#

How to print values inside TheoTown.getStorage()?

weak mural
#

with the key.

rare grottoBOT
#
Case #9VuJQX

je ne fais pas de vรฉlo#7379 has been warned: off-topic.

winter vapor
#

N o

elfin geyser
#

Hmm how to create listbox without borders? Just the item's canvas only

potent jolt
#

Use a custom 9patch for it?

#

Idk if that's an available option

#

I'm pretty sure there's a way to access the underlying UI elements

elfin geyser
#

I tried but doesn't work, also the on draw thingy

weak mural
#

you can make it yourself. it's easier to customize.

potent jolt
#

or that

elfin geyser
#

Clueless bear_think

#

Wait is that your open source dev tool?

potent jolt
#

title implies so

#

open source?

#

i see no repo of it

#

i think its private

random hamlet
#

Erksmit troled

weak mural
#

yeah, i made it private after someone tried to steal in-game textures.

elfin geyser
#

I don't think if it's possible to had custom color for buttons, if not i wish this may include soon

weak mural
#

isn't there a frameDefault parameter?

elfin geyser
potent jolt
#

why not provide a single pixel of color

elfin geyser
#

Does this will work on theory?

What i mean about this is can i cached values to module on init, that later can be called?

weak mural
#

yes, you can.

-- module
local module = {};

local var = 1;

module.var = 2;

function module.getVar()
  return var;
end;

function module.setVar(value)
  var = value;
end;

return module;```

```LUA
-- main
local module = require('module');

print(module.var);
print(module.getVar());
module.setVar(3);
print(module.getVar());```

-- output
2
1
3
elfin geyser
#

Why your code has semicolons?

potent jolt
#

lol

#

must be a mistake

weak mural
#

to skip vsc snippets. lol

elfin geyser
#

How to fix? Im pretty sure i put the right path

potent jolt
#

No luawrapper?

elfin geyser
#

Already fix forgot to mention :)

errant mantle
#

H

elfin geyser
#

Oh hi?

elfin geyser
#

Is there any function to get touch points like how "show touch point" Setting does, as of now i just used script:tap() and script:update() for this

random hamlet
#

Why u need to make ur own cursor lmao

elfin geyser
#

For my self lol

random hamlet
#

Ah

solid scarab
#

can anyone teach me to do cars and make a spawner for them?
DM me

elfin geyser
uncut field
#

If I draw text to the screen, is there a way I can determine its width?

potent jolt
#

This tells you how wide a drawn text would be

uncut field
#

Thank you, and thank goodness for that

#

That will make my work a lot easier

idle musk
#

[ { "frames":[ { "bmp":"seoul162.png", "count":4, "h":17, "w":20 } ], "id":"$seoul16200", "influencepassengerbus":10, "speed":0.9, "type":"car", "v2":true }, { "author":"gmt2948", "carspawner":[ { "cars":[ "$seoul16200" ], "count":5, "radius":90 } ], "category":"$cat_bus00", "drawground":"true", "frames":[ { "bmp":"seoulstopb2.png" } ], "height":1, "id":"seoulBUSstopb2", "influencepassengerbus":22, "monthlyprice":600, "price":50, "text":"seoulBUSstopb2gmt2948", "title":"seoulBUSstop2", "type":"public", "width":1 } ]

#

How can I rotate the bus stop in four directions on this code?

random hamlet
#

Can we rename this channel to #fun-lua-scripting

full topaz
#

Fun n confusing lua ๐Ÿ‘

weak mural
#

trust me, fun is more complicated than lua.

light plinth
#

it aint

#

and its faster

potent jolt
#

ok

#

then where is the fun documentation

light plinth
potent jolt
#

im not reading that

slate oxide
random hamlet
#

I'm just saying its a wrong channel

#

Im not saying im "smart" as you "pointed" out

slate oxide
random hamlet
#

but this channel is for discussing about fun and about lua

gentle canopy
#

Bus stops doesn't require some "privileged code" for work?

random hamlet
#

yes thats what I said

slate oxide
#

or make for json itโ€™s own channel

winter vapor
#

discord arguement

slate oxide
#

and also 100+ channels

merry shale
winter vapor
merry shale
slate oxide
#

wait really

potent jolt
#

okay

slate oxide
#

letโ€™s make json channel

potent jolt
#

if you want anything changed

#

put in a suggestion

#

cuz this argument is going nowhere

gentle canopy
winter vapor
merry shale
#

idk what that ratio thing even means ๐Ÿ—ฟ

random hamlet
gentle canopy
random hamlet
#

what im saying that next time he should post json in another channel

gentle canopy
potent jolt
gentle canopy
#

Lel

merry shale
random hamlet
#

tf is ratio ๐Ÿ˜ก

#

I semi-understand what based means

random hamlet
#

good

winter vapor
#

lmao pepl here keep talking about the argument

gentle canopy
#

Emmm... why the plugins need to confirm multiplayer? Shouldn't every TT version at least support multiplayer at this point?

potent jolt
#

anyways yes

#

its about time to stop

potent jolt
slate oxide
gentle canopy
#

Lol

potent jolt
#

maybe has something to do with lua networking

gentle canopy
#

Question
Plugins can get graphics information from other plugins?

potent jolt
#

yes

gentle canopy
#

Noice

potent jolt
#

actually

#

what kind of information do you want to get

gentle canopy
#

Like, height and wide, or if possible the plugin image, Im seeing if something like "Shadows, finally" is possible

potent jolt
#

you can retrieve the frame object of a building

#

and get their height as well

#

dunno about width though

#

im not sure how much stuff you can do with the frame object

gentle canopy
#

Just getting the numbers
Im planning to draw the shadows using vectors
Idk what to do with terrain height, lul

#

Also, Idk how performance will go, lul

potent jolt
#

hmm

#

not sure how you will be able to tell between building and baseplate

#

it probably wouldnt run too well

#

but probably fine for high end phones and pc

gentle canopy
#

Who cares about performance anyways

#

I mean, look the game, is running in Java

potent jolt
#

you should be fine for performance

#

you can always try to optimize

#

like generating shadows on startup by draft

random hamlet
#

whatcha doing

gentle canopy
#

Well, since I dont think I could storage the shadows in the texture image, because... no
I was imagining like drawing the shadows every frame = no FPS

#

Emmm...

random hamlet
#

didnt know you were a lua coder to be honest

gentle canopy
#

It could just be a generic texture stretched according to the height and wide of the building, since TT graphics are pixel-art I dont think low resolution could be a issue

gentle canopy
#

Then use the building texture as a mask to avoid the shadow being adobe the building

potent jolt
#

youll have to use the drawing module to draw the shadopw

gentle canopy
#

Welp

#

H

random hamlet
gentle canopy
#

Well, Im not expecting it for work, just for experimentation and fun

potent jolt
#

i dont think itll be possible

#

itll be too hard to diffrentiate between a buildings baseplate and the building itself

gentle canopy
#

Buildings baseplates?

#

Ah

#

Textures can be draw outside the building itself right?
Since shadows are a requirement for plugins and buildings
Like, a 4x4 building, drawing the shadows outside that 4x4 space

potent jolt
#

if you set the handle you can do that

#

but it might clip into other stuff

#

but like

#

if someone has a baseplate in his graphics

gentle canopy
# potent jolt but it might clip into other stuff

Emmmm, it could use the height data to handle that
Like, if behind the 4x4 building were a tall 4x4 building, the portion of the shadow that should be colliding with the building could be draw in a different direction
For know where the building is, it could verify if there is a building in the shadow path

random hamlet
#

I don't think this is possible to do

#

At all

#

Even for someone who is very experienced

gentle canopy
#

Well, you dont know until you try it

#

Also, what is wrong with not being experienced?
As I said before, Is just for fun and eventually to get some experience

random hamlet
#

I think it's just not possible

#

I'm not saying it's wrong not to be experienced

#

I just think that people with a lot of experience in Lua coding can't do this, I don't think shadows are possible

#

You can't really say "you don't know until you try it" because you usually read a documentation and imagine an algorithm

#

Btw sorry if being too negative

#

Even if you somehow could get correct shadows for each building it would still be very tricky to draw them

gentle canopy
#

Well, even if it dont work, or even if it works in a basic way
For example, something more simple, and this is an idea I had for a while, animation for trees, dividing the trees in different parts, and make them react to different situations
Or an tool for create shadows automatically, not necessarily to being useful, but more like a way for me to get used to lua
As I said, Is just for fun, I dont want to make a plugin that I could sell in the plugin store, or even a free plugin in the forum, just for fun, as experiments, I dont publish my plugins, I only use them as a way for me to experimentation, I barely have enough time to play TT, I wont have enough time to support a plugin

#

Just some probably insane ideas I get from time to time, and even if I waste my time, is just for fun
I dont want to get diamonds, Im not interested in publish plugins, Im interested in learn

random hamlet
#

I recommend you start with something more basic and then slowly do more advanced things

gentle canopy
#

Emmm... In that case, some simple UI, like panels, sliders, etc

random hamlet
#

If you want to make ui plugins then yeah

#

ui is pain

gentle canopy
#

h

elfin geyser
#

Does script:daily is same speed as script:update?

torpid spear
#

those are two completely different things

#

update is every frame, daily is every day

#

also script:daily is not script:nextDay (probably)

elfin geyser
elfin geyser
torpid spear
#

you're welcome

potent jolt
#

Or other drawing shapes

potent jolt
#

Gotta read the documentation carefully to not switch them up

#

Nextday gets called once every day

#

Daily gets called for every building of the draft the script is attached to

potent jolt
#

I think the main problem is

#

You can't really see what's in a frame

#

At least

#

I don't know of any functions for that

torpid spear
#

I'd ask ian

#

his anim dev tool could have some important functions

potent jolt
#

I don't think that manipulates a frame though

#

Just generates animation json

torpid spear
#

I have no idea

weak mural
#

scale up like this? bear_think it's better to directly draw the right size.

#

however, scaling down will make the frame smoother, some icons are scaled down, like Icon.CLOSE_BUTTON.

torpid spear
#

target w, h โค๏ธ

stoic vector
#

Big theoman