#plugin-lua-and-fun

1 messages · Page 3 of 1

native timber
#

practicing is easier for me

torpid spear
#
  1. me blatantly pointing out your mistakes won't make you learn, you'll have to figure it out on your own
#
  1. you've got the whole internet to browse, get searching!
#

there's a whole lot of websites that teach you lua because I've used some of them ages ago

native timber
#

you don't understand, it's physically easier for me to just look at the code and think how it works, and all the guides I find fall into three types

  1. GMOD
  2. general information
  3. roblox
torpid spear
#

then get learning, and good luck

#

you're gonna need it

native timber
#

I just hate to sit and read boring documentation, so I'm much happier sitting and pounding on non-working code to figure out how to fix it

torpid spear
#

you're free to find some

native timber
#

thank you, you almost put me off learning lua.

torpid spear
#

that's your choice, I told you what to do

native timber
#

I'm just asking for help with the script, you don't have to tell me how to learn.

torpid spear
#

I also told you what to fix in your script, I'm not writing lua for you

native timber
#

I understand the help, but I already found the guide.

#

I said, I'm a newbie, I have NO clue how to fix this one, I don't know what you mean when you say I'm accessing boolean incorrectly and that some values I can find in the json forums.

torpid spear
#

that's why I told you to read some documentation

#

you won't learn what a boolean is by just looking at someone's code

#

learning is a balance of theory and practise, you can't just skip one part and expect it to work

native timber
torpid spear
#

you are trying to write a lua plugin for theotown

#

it's obvious that you're gonna need lua knowledge for that

#

also, what is "general scripting" to you?

native timber
#

I'm doing it the way I know how, the fact that I'm accessing a boolean incorrectly doesn't mean the whole code is wrong, so I'm asking for help.

native timber
torpid spear
native timber
#

they are unlikely to help me understand what budgetitem is or where to use City.

#

how do I fix them?

#

to study for a month only to realize that I made a small error in syntax?

torpid spear
#

City is the module, which you'd have known if you studied basic lua theory

native timber
torpid spear
potent jolt
#

what are you trying to do\

#

at a high level

#

whats the goal for your script

native timber
#

I don't want to learn three weeks to finish a script I made for an example, I'm sure it can be fixed in a minute now, but I have no idea how. I'm writing it to figure out how to structure and write it, and you're telling me I have to learn it, even though I'm writing it to learn it

potent jolt
#

well you are

#

but it will probable be like 3 weeks before you arrive at a usable script

native timber
# potent jolt whats the goal for your script

The purpose of this script is that if there is a certain building on the map, and if the profit exceeds the city budget, a certain amount of money will be added to the player's bank every month.

torpid spear
#

lol nobody prepared you for the fact that programming isn't something you learn in 5 minutes

potent jolt
#

well that is possible

#

but you really ought to focus on the fundamentals for lua

#

but this can be a good exercise for it

torpid spear
#

now, can we see the actual code

native timber
#

.

torpid spear
potent jolt
#

well theres some indent problems that make it hard to read

#

your variables have just a single letter

#

you should pick a descriptive name for them

torpid spear
# native timber .

removing that redundant space in the first line would be a solid first step

potent jolt
#

you should right click -> format document

native timber
potent jolt
#

no

#

it just changes your indenting

native timber
native timber
torpid spear
#

in your ide...

#

right click and format the document

#

(I assume you changed the language to lua already)

native timber
potent jolt
torpid spear
#

right click

#

with your mouse

potent jolt
#

i literally told you to right click

native timber
potent jolt
#

i cant help you if youre not reading

#

also you still have 2 lua plugins installed

native timber
potent jolt
#

you should only have 1 active

#

i am using sumneko.lua

torpid spear
native timber
torpid spear
#

but it could probably help to have something

native timber
torpid spear
native timber
torpid spear
#

uninstall it

#

don't need it

native timber
#

what i need in this way

torpid spear
#

no plugins

#

0

potent jolt
#

now that your file is formattted and looking nice

#

you should rename that a b and c

#

to something that actually represents the value they hold

torpid spear
#

like a => currentEstate

#

and similar

native timber
#

sec i will fix it

potent jolt
#

thats looking nicer

#

next time you can use f2 or right click -> rename symbol

#

that way it will rename it everywhere

torpid spear
#

double control+r renames variables in all occurences so you might want to use that

native timber
torpid spear
#

oh that might be something from regular vs

potent jolt
torpid spear
#

smh

potent jolt
#

or resharper

#

idk

torpid spear
#

yup it's a vs thing

#

idk vsc

potent jolt
#

its f2

torpid spear
#

shortcuts

native timber
#

bruh guys

torpid spear
torpid spear
zinc isle
#

never seen this channel this active

torpid spear
#

i'd recommend naming it "buildingCount" or something like that since it doesn't actually answer the question "is"

#

you also have some typos

#

some as in atleast one

#

you need precision when you're scripting

native timber
#

That's not the point here

torpid spear
#

then what is

potent jolt
#

also earning income is restricted to privileged plugin creators

#

@light plinth can help you with that

native timber
#

IsBuldingIn equals the number of buildings in a certain id in the city

#

no idea how to convert it to boolean

light plinth
torpid spear
#

I'm telling you that it's nice to have a uniform naming scheme and not use names starting with "is" for representing integer types

#

but, anyway, fix the citymoney typo

#

bunny, you're clueless when it comes to lua, stop even watching this chat

native timber
torpid spear
#

well that's an interesting name

#

now let's see the whole thing

zinc isle
native timber
#

whats next

torpid spear
#

did you fix the typo

#

I'm asking this the third time

native timber
#

CityMoney?

torpid spear
#

yes

native timber
torpid spear
#

show me the whole code, not completely random 1 line snippets that tell me nothing

native timber
torpid spear
#

no you did not fix it

native timber
#

lol

#

srry

torpid spear
#

anyway, you wouldn't use a while loop here

#

the code runs only once every month, there's no iteration needed

native timber
#

I just realized...

#

ok

#

if then?

torpid spear
#

make it a single if statement and type all your conditions in there

#

brackets () and and statements will help here

native timber
native timber
#

wrong?

torpid spear
#

your indents/ends don't match here

#

take a closer look

native timber
torpid spear
#

😩

#

it works, but you made it look horrid

#

an if body needs an indent, not 2

#

then you close it

#

and so it goes

native timber
#

there is a function in a start

noble hedge
#

pretty sure he needs json "privileged":"*********" on his jsons to function that ```lua
City.earnMoney()

torpid spear
noble hedge
#

my bad

torpid spear
#

no problem

#

good thing to notice

native timber
#

I don't think I get it

#

you mean the two end at the end?

torpid spear
#

function ...
stuff
if something then ...
stuff
end
end

#

that's how indentiation works

#

please learn lua theory 😩

native timber
#

what wrong

torpid spear
#

format document again and see for yourself

#

it's not wrong, per se

#

damn my soundtrack album looped like thrice now..

native timber
#

I understand the problem is the structure

torpid spear
#

the only thing that should be left to fix is to remove the optional, redundant parameters from the earnMoney function

native timber
torpid spear
#

that should do it, in theory

#

now format the document and make sure it's actually attached

#

attached as in json

native timber
#

as I realized, the main error was in the format and space in the function

torpid spear
#

yes

native timber
#

dont working tho

torpid spear
#

define not work

#

is it attached in json

native timber
#

It's a new month, budget is 1,000, profit is 111.

torpid spear
#

income won't work without a privileged key

native timber
native timber
torpid spear
#

also, earnMoney simply adds a value to estate, so the income readout won't be accurate

torpid spear
#

you might want to add an additional Debug.toast('text') in your script to detect whether it actually does something

native timber
#

No, I just have no idea what you mean, what's the key? I'm not a native English speaker, it would be very hard for me to find it in the dialog now.

low jewel
# native timber ???

what he refers as a "privileged key" is a thing some trusted plugin creators have

torpid spear
#

you need to be an approved plugin creator before you can use op features like income or diamond spending

low jewel
#

^

low jewel
#

without a privileged key you can't do that

torpid spear
#

you have been warned before

#

also do what I said and check if the script actally works

native timber
#

debug working so

torpid spear
#

there you go, you created a lua plugin

#

congratulations

native timber
#

🥳

#

so

#

why earnmoney dont work

zinc isle
#

because youre not allowed to use it

torpid spear
#

learn to read, god

native timber
#

how does my Discord have anything to do with the game? lol

torpid spear
#

you've been told several times

torpid spear
#

this chat would be half as large if you were to actually read our remarks

zinc isle
low jewel
#

you don't have a privileged key

#

please read

zinc isle
low jewel
#

thank you

torpid spear
#

the process is: create good plugins > apply for privileged code > get code > use said code > profit (literal profit)

native timber
torpid spear
#

basically

native timber
#

bruh

torpid spear
#

income above 1t is restricted for anyone who's not privileged

#

simply because people would create 1x1 buildings that generate millions of theons per second...

native timber
#

I mean, I can only make the income for this building less than 1000?

torpid spear
#

at most 1T

#

one theon

native timber
#

and how hard do you have to work to get the key?

low jewel
#

well

torpid spear
#

at least that's how it worked for json, no idea if it's the same for lua

low jewel
#

quite hard

torpid spear
#

create a few quality plugins

#

and that's it

native timber
#

ok

#

wait

#

and what's stopping me from making 100 buildings for a profit of 1,000?

low jewel
#

a privileged key.

native timber
#

and, I understand this is a limitation in both Lua and json.

low jewel
#

ah yeah

#

nvm I read that

torpid spear
low jewel
#

you can't

torpid spear
#

json for sure

#

you'd have to read more about those lua functions

#

anyway, your script isn't tied to a single building

#

so count doesn't matter here

native timber
#

it blocked so

#

earnMoney in lua

#

just dont working

#

still

#

thanks for help

#

so much

potent jolt
torpid spear
#

you're welcome

#

lua is a very powerful tool

zinc isle
#

lua seems like a pain in the butt too

torpid spear
#

if you have 0 scripting experience, yes

noble hedge
#

Is real time Lua editing still works on mobile?

torpid spear
#

why wouldn't it

noble hedge
#

Gonna try

noble hedge
#

Real time Lua editing doesn't work on me (is it broken?), it still needs to import on file manager (I mean, requires restarting)

elfin geyser
#

You need to save it on every changes you've made

noble hedge
#

so it's not realtime?

#

I already saved it everytime I make changes though I cant see the result on realtime

noble hedge
native timber
#

yo

#

why i cant call a function

#

The game shows an error at startup, they say it requires a closing } on line 13, although it is not needed there, if I replace Plus() with function(), it will work

potent jolt
#

youre running plus() and giving onClick its result, instead of giving plus itself to onClick

native timber
#

i need to do something like onClick.Plus()?

weak mural
#

onClick = Plus
or
onClick = function() Plus() end

native timber
#

thx

native timber
#

guys, is the setXp command blocked by the privileged key?

torpid spear
native timber
#

😦

native timber
#

yo

#

why game saying getX and getY a nil value?

torpid spear
#

there are no such functions as getX or getY in the City module

native timber
#

oh

#

Building module?

torpid spear
#

that looks like the only module that has those functions

native timber
torpid spear
#

yes I have access to the api

native timber
#

wtf

#

game gave me a error on -1 line

#

nil value with isValid

torpid spear
#

how does your code look like

native timber
#

i think slider code is wrong, but i just teaching it now

torpid spear
#

functions getX, getY don't have overloads for drafts

#

they operate on building types

potent jolt
native timber
#

then, how i need to write it? dont see this information on API site

potent jolt
#

you use city.getbuilding

torpid spear
#

you first get the building and then operate on that

#

you can't get the position of a building if you don't have the building

native timber
#

i need to use City.getBuilding with draft to get XY a then operate with them

#

got it

torpid spear
#

yes

native timber
#

If I write a variable with the value City.getBuilding it will have the value X, Y? Like 64, 76.

torpid spear
#

?????

native timber
#

mmmm

torpid spear
#

I have 0 idea what you're trying to ask me

#

City.getBuilding returns the position of a building of specified index

#

you'd need to have the index

native timber
#

still nil value lol

torpid spear
#

"$pcw_66cae77f27fa00" does this look like an index to you

#

it's an id string

native timber
#

wait

#

oh

torpid spear
#

indices are positive integers

native timber
#

where i need to find index? Building.getId()???

torpid spear
#

id != index

#

each building in the city has its index

native timber
#

😦

torpid spear
#

I don't know what do you want to do

native timber
#

how i can know it?

torpid spear
#

you'd probably iterate through every building of your draft

native timber
#

where i can find building's index?

torpid spear
#

I have just told you

#

count all buildings of your draft and iterate through each of them

#

I can't help more, I don't know what do you want to achieve

zinc isle
#

iterate 😩

noble hedge
#

patience kulche patience

torpid spear
native timber
#

Okay, in another way, how do I use City.getBuilding?

torpid spear
#

you input the index and it returns two int variables - x and y

native timber
#

how do I know the index of a building? (I can't understand what you were saying before, I mean, go through all the buildings from draft?)

torpid spear
#

I have already told you, each building in a city gets assigned an index

potent jolt
#

thats the nice part

#

you dont

#

you dont know what building youll get from a certain index

#

but if theres only 1, you can be sure its that one

torpid spear
#

it gets much easier when you have maximum 1 building of the same draft

#

yes

native timber
#

And where do I get the index? I realized that it is different in the city and unique for each building, but what then?

potent jolt
#

index of 1 = 1st building

light plinth
#

Building tables are stored in lists that you can access using City.getBuilding(draft_id, index of the building in the list)

You can obtain how many buildings there are in the city using City.countBuildings(draft_id) or something similar.

Then it becomes a trivial loop to get the building that you need.

torpid spear
#

if you have maximum 1 building of the same draft you can simply use City.getBuilding(1, draft)

#

starting indexing at 1 🤮

potent jolt
torpid spear
#

lua moment

potent jolt
#

i had to write complex industry in this

noble hedge
#

shame on lua

native timber
#

still wrong

potent jolt
#

should work

torpid spear
#

it returns 2 variables

native timber
torpid spear
#

you only assign 1

potent jolt
#

well

#

are you in a city?

torpid spear
#

I'm not sure if that's a problem in lua

potent jolt
#

(its not)

#

it simply discards the rest

torpid spear
#

good

native timber
potent jolt
#

same with function arguments

#

feel free to toss 50 arguments into a function

#

well

#

are you in a city?

#

becuase your error says the city table doesnt exist

#

which indicates that you are not inside a city

native timber
#

i cant to come in game

torpid spear
#

then you're calling the script improperly

#

call it when you're in a city, not immediately =

native timber
#

got it

potent jolt
#

you must be calling it in script:init

#

you should use another function instead

#

something like nextDay, which only runs inside cities

native timber
#

script:enterCity

potent jolt
#

that ought to work

native timber
#

ok, im in city, but game says that x and y = nil

#

bruh

#

oh wait

potent jolt
#

well

native timber
#

i forgor to place building

potent jolt
#

is your building in the city?

native timber
#

lol

torpid spear
#

lol

potent jolt
#

that might help

torpid spear
#

skill issue

native timber
#

good joke so

potent jolt
#

anyway should be all good

native timber
#

nil...

torpid spear
#

you have to place the building, save and reenter the city

native timber
#

building on the top right

#

but still nil nil

potent jolt
torpid spear
#

yeah and

potent jolt
#

it would call entercity again

torpid spear
#

hm

#

show lua

potent jolt
#

are you sure your draft id is correct

native timber
#

I GET IT

#

I'm gonna try something

potent jolt
#

by the way you can use script:getDraft()

#

that way you dont have to manually put in the draft's id

native timber
#

I changed script:enterCity to script:nextDay, thought it would help (lol no)

potent jolt
#

ah

torpid spear
#

you don't have to create two identical functions, you can put the toast in the function at the top

potent jolt
#

yea you cant define nextDay twice

#

the 2nd will overwrite the 1st

#

thats why x and y are nil, the first one is never ran

native timber
#

do I need to remove the second function?

potent jolt
#

yes

#

you can put the debug toast in the first function

native timber
#

WORKS🥳 🥳 🥳

#

where's my button?(((((

potent jolt
#

well

#

you never obtain the dialog youre trying to add stuff to

#

you have to change the signature of your finishInformationDialog function to include it

#

like (x, y, _, dialog)

#

im using _ for the 3rd argument to discard it

native timber
#

thanks

#

and there a question

#

how to make notification like that?

noble hedge
#

I guess there's a notif tutorial under fun attributes on forums

#

Ahh yes

native timber
potent jolt
#

theres a function for that

#

should be over in the city module

native timber
#

oh thanks

#

and so

#

where i can find all game icons or actionPlaceType's

potent jolt
#

you can install the plugin developer tools plugin by lobby

#

it contains some example gui code and a list of available icons

native timber
noble hedge
#

I would like to add an external link on my dialog box, what lua function is that?

lost zenith
#

how to make a fence plugin?? where I need to go

torpid spear
#

not lua/fun related

lost zenith
#

sorry

#

so I need to copy the script too?

torpid spear
#

what?

#

script?

#

fences are in no way related to scripting

lost zenith
#

oh

opaque lake
#

What is plugin-lua-and-fun about? Like what do you do here?

opaque lake
#

Ok

noble hedge
#

Is tollbooths created using fun attributes? Or how it was implemented?

light plinth
#

Lua

native timber
#

From this function I expected that it will simply every game day to increase the number by one and output, but it just takes and from the beginning starts to output 5, wtf?!

#

sorry, wrong, it doesn't output 5, it alternates 1 and 5 in a row in the output

potent jolt
#

there is probably some code offscreen that messes this up

#

but it falls outside your screenshot

native timber
#

nope, all the code behind the screen is written with --[[, and it doesn't matter, basically it's just the code for which I need the counter, so I removed it for a while.

torpid spear
#

show your whole script

weak mural
#

use local for the first emae

#

use ~= | < | <= | >= | > instead of not 1 == 100

potent jolt
#

ah

#

you might accidentally attempt to invert amae

#

what it is doing is first negating emea, then comparing it to 100

native timber
#

It's working now, but in a weird way

#

it first outputs 5 and then the number in order (5, 1, 5, 2, 5, 3...).

torpid spear
#

make breg local

native timber
#

I can't, breg is used in two script functions

#

ok, now it local

potent jolt
#

well that just sounds problematic

#

also you can still make it local

native timber
#

i fixed it

#

it still 5 lol

#

now it starting to working VERY bad

#

it only 5

potent jolt
#

look there must be more to your script then

#

i really dont trust that thats all

#

because if it was it wouldve worked

native timber
#

even so,a equals two and five. I DON'T KNOW WHAT'S GOING ON

#

my lua broken?

potent jolt
#

well now youre just assigning 1 to it every day

native timber
potent jolt
#

youre setting it back to 1 every day

native timber
#

i know

#

that's the reason I made it global, but if I make it global now, it'll go back to alternating with an 5.

potent jolt
#

you can put locals outside your functions

#

they dont need to be global for that

#

global just makes it manipulable by other scripts

#

which is dangerous and you shouldnt do it

native timber
#

I know, I know, but now we have to figure out why it's alternating five

potent jolt
#

just put it as a local outside the dailt function

native timber
#

i fix it

#

i just made it random

weak mural
potent jolt
#

to be fair, lua's official documentation is really bad

stoic vector
#

i agree

noble hedge
#

I strongly agree

elfin geyser
#

Accede

uncut field
#

It also doesn't help when the version of Lua I use is 15 years old

noble hedge
lucid summit
#

what?

#

Interesting?

potent jolt
#

its neat

lost zenith
cerulean crypt
nimble sun
#

You know exactly what it is...

torpid spear
#

this is gonna fry your device lol

light plinth
#

oh god

potent jolt
#

finally, theotown is now a real game

south garnet
#

Lmao

#

We just have to wait until somebody runs doom in TT

nimble sun
stoic vector
#

someone is actually doing it

potent jolt
#

how is the video stored in the script

nimble sun
potent jolt
#

dear god

#

perhaps you could check if a tile actually needs to change before placing new tiles

#

to reduce the amount of calls to java

#

or just draw it with drawing calls

light plinth
#

Alternatively, convert it to fun

#

Not sure if that will be faster tho

nimble sun
#

I dont know TT api very well yet, so optimizing is a bit difficult :DD
according to the docs, i can use buildGround with drafts
like

Builder.buildGround('$black', 10, 10)

but
i guess using buildings for this is bad idea

light plinth
#

I would probably check the previous frames, rather than call to TheoTown to check if tile ground draft equals current frame that is required

#

Hope you cache Draft.getDraft call

nimble sun
potent jolt
#

thats gonna hurt performance

light plinth
#

I would love to open the game timings while it's running

#

lol

potent jolt
#

prevents having to do any fps related timing because its gonna run slow anyways

light plinth
#

lol

#

says the guy with amazing fps dependant rocket animation

potent jolt
#

see, not setting the lastms simply adds to the exponential increase in speed

#

its a feature

nimble sun
#

switched to ground
pain

light plinth
#

missing edge frames

#

or something

nimble sun
weak mural
#

lol 1.10.42?

nimble sun
potent jolt
#

probably means the game doesnt have to figure out as much about how to place it

#

getting the draft object on startup and using that should improve performance too

nimble sun
potent jolt
#

using the drawing module would probably give a massive performance boost

potent jolt
#

doesnt have to be

#

you can draw on tiles if you want

#

here i am using drawing

#

which is also why it looks terrible

zinc isle
#

piccle

potent jolt
#

as you can see its drawn in relation to where the building is

potent jolt
#

yea

#

combined with setTile

nimble sun
#

thx, let me check this

potent jolt
#

youll have to get the black and white frames from the drafts

nimble sun
potent jolt
#

not ingame

#

but in the theotown folder in your userfolder there is a log.txt file

#

also, you tried to call setTile while not inside a city

#

youll have to use a different event function to run your code

#

script:drawCity () is a suitable one

nimble sun
nimble sun
#

or maybe texture..

potent jolt
#

try putting your getDraft in script:init

#

as ```lua
local black

function script:init()
black = Draft.getDraft('$black')
end

function script:drawCity()
Drawing.setTile(5, 5)
Drawing.drawTileImage(black)
end

nimble sun
potent jolt
#

i think drawcity might be too new for your game version

#

let me check real quick

nimble sun
#

1.11.13p

potent jolt
#

dunno

nimble sun
# potent jolt dunno

i guess json

  {
    "id": "$black",
    "type": "ground",   
    "author": "Neon",
    "width": 1,
    "height": 1,
    "frames": [
      {
        "bmp": "flatblack.bmp"
      }
    ],
    "edge frames":[{"count":12,"h":48,"w":16,"x":0,"y":96}],
    "level": 1
  }

maybe you can check your json with pickle idk

potent jolt
#

did you specify your script anywhere

nimble sun
potent jolt
#

maybe put a Debug.toast in your drawCity and see if it shows up

#

or check the logs

potent jolt
#

call Drawing.reset before drawing

#

just in case someone else set the opacity or something

#

ah i see the problem

#

my script was passing the draft instead of the frame

#

it should be

local black 

function script:init()
    local draft = Draft.getDraft('$black')
    black = draft:getFrame()
end

function script:drawCity()
    Drawing.setTile(5, 5)
    Drawing.drawTileImage(black)
end
nimble sun
#

also, checked image with drawImage - works

potent jolt
#

you can probably just use drawImage, if your tile image aligns with the tile

nimble sun
#

also, seems like storing big table with pixels in memory cause game to freeze every n seconds
even if not using it(

potent jolt
#

if you have used setTile it will be drawn on the tile's location

#

drawImage should end up exactly on the tile you set

#

this is what ive used and it works for me ```lua
-- Draws an icon ontop of a building indicating the building has a problem.
---@param draft draft The draft of the building.
---@param building industriBuilding The industriBuilding that has a problem.
local function drawProblem(draft, building)
-- check if the building actually has a problem, and ignore the SUPPLY_NOT_MET problem since the game already draws an icon for that.
if building.problem and building.problem ~= IndustriBuilding.PROBLEMS.SUPPLY_NOT_MET then
-- get the center position of the draft
local width = draft:getWidth() * 32
local icon = Industri.getIcon(building.problem)
-- use the width of the draft and the size of the icon to get a offset that will center the drawing
local offsetX = (width - Drawing.getImageSize(icon)) / 2
-- draw the icon in the center of the building, 60 pixels above it
Drawing.setTile(building.location.x, building.location.y, offsetX, -60)
Drawing.drawImage(icon, 0, 0)
end
end

potent jolt
#

it wont work without a lot of additional surrounding code

#

its just a snippet i grabbed

nimble sun
#

yea I see

potent jolt
#

ah

#

the x and y argument for drawImage are not optional

#

i just use Drawing.drawImage(icon, 0, 0)

nimble sun
#

thinking about random freezes due big table

as I understood, here I can’t use any external things like luvit
or access os/io from lua ingame

potent jolt
#

no, theyve been blocked for security

nimble sun
#

understandable(

potent jolt
#

can i try the earlier version that worked

#

i want to see the performance

nimble sun
nimble sun
#

"Will be called once per frame after UI has been drawn. Will also be called outside of cities."

badapple-v is just a lua file with one (large af) table

  {
    "id": "$badapple-v",
    "type": "script",
    "script":"#LuaWrapper",
    "meta":{
      "luawrapper":{
        "script":"file.lua", 
        "dev":true               
      }
    }
  }

then why does debug show this..?

nimble sun
#

is there any legal way to disable this profiler or idk how to call it
it measures timings every second and it causes game lag (big table :D)

zinc isle
#

theres a setting for that in settings

nimble sun
nimble sun
#

this looks pretty good already
but every-second lag is killing me

here i loaded only ~1000 from ~6600 frames to reduce lag time
but still bear_sad

||also irl it looks better, some recording issues||

zinc isle
#

pretty cool

light plinth
#

I feel like that will be the garbage collector, rater than the timings measuring

nimble sun
potent jolt
#

perhaps you can store parts in diffrent draft's meta tags, then load those piece by piece

#

theyll still be entirely loaded in java, but maybe that wont lag as much

nimble sun
#

looks like only way i have is splitting them to ~500 frames and record one by one
but this is cheating(

#

at first I thought maybe i can provide frames using tcp or smth
but since i cant use anything external..

nimble sun
#

looks like using strings is better than tables bear_think

nimble sun
light plinth
#

Amazing

nimble sun
potent jolt
#

overall, not the worst

nimble sun
#

maybe one day we’ll have way to get pixels from another sources and it’ll able be to run doom

potent jolt
#

doom would honestly probably be easier since you dont have to store an ungodly amount of data in memory

#

besides having to run doom

nimble sun
#

maybe there is some chance of getting an "unsafe" mode for lua idk

#

maybe io.popen is enough for running complex things, dunno bear_fire_st

potent jolt
#

io module doesnt exist in TT's lua environment

nimble sun
nimble sun
cerulean crypt
#

Hello i need help about fun,
There's any documentation about creating new notification convo by pressing check or ok?

noble hedge
cerulean crypt
#

Can u give a sample

zinc isle
#

shush dyno

noble hedge
#
"id":"$cool_notif",
"type":"notification",
// ...
"question":true,
"ok fun":[
  {
    "actions":[  
      //stuff  
    ]
  }
],
"cancel fun":[ // optional
  {
    "actions":[  
      //stuff  
    ]
  }
],
// ...

coolio!

#

more cool stuffs on lua

cerulean crypt
#

Thanks

#

Ill try it

cerulean crypt
torpid spear
#

jesus, format your jsons

#

also, do you need ok fun if you aren't going to use it

cerulean crypt
#

Thats fine its for future messenge convo

icy siren
cerulean crypt
#

My problem is it won't work

noble hedge
#

I dont think, nested fun is working

torpid spear
noble hedge
#

yeah definitely won't work

torpid spear
#

you're supposed to put those arrays in your notification definition

#

not building

#

or whatever calls those actinos

noble hedge
#
{
  "id":"$dummy_object.trigger_mess",
  "fun":[ // you may use `on click fun`, or `random fun` here
    // triggers your notif message
  ]
},
{
  "id":"$notif_message_00",
  "question":true,
  "ok fun":[
    // triggers next ok message action
  ],
  "cancel fun":[
    // triggers next cancel message action, optional
  ]
},
{
  "id":"$notif_message_00_ok",
  "question":true,
  "ok fun":[
    // triggers ok action
  ],
  "cancel fun":[
    // triggers cancel action
  ]
},
{
  "id":"$notif_message_00_cancel",
  "question":true,
  "ok fun":[
    // triggers ok action
  ],
  "cancel fun":[
    // triggers cancel action
  ]
}
#

it basically notifies user, and after they answer ok (check mark) on the first notif, the second notif (00_ok) will appear
or if they cancel (cross mark) the first notif, the third (00_cancel) notif will appear

cerulean crypt
#

Oww thanks for effort

noble hedge
#

coolio

cerulean crypt
potent jolt
#

further fun actions

#

whichever you want

noble hedge
cerulean crypt
#

Yah i already figured out that
Im still confused about making message convo

noble hedge
#

"actions":[{"type":"notify", "id":"$notif_message_00"}]

cerulean crypt
#

It is possible to add color on text?
||no lua pls||

light plinth
#

no

cerulean crypt
#

Sad

cerulean crypt
#

Help

{
                                "id":"$notify_discription_abandoned_tanker_upgrade",
                                "type":"notification",
                                "text":"Starting now, this tanker will be operational again.",
                                "frames":[{"steal":"$anim_people_source01","frame":10}],
                                //"question":true,
                                "fun":[
                                {
                                "actions":[
                                {"type":"rect","w":1,"h":1,"inner":
                                [
                                {"type":"remove"},
                                {"type":"build","id":"$rusty_industry1","z":1}
                                ]
                                }
                                ]
                                }
                                ]
                                },
noble hedge
#

If you wanna use "inner" your type should be "type":"or" or "type":"and"

noble hedge
#

no condition, direct into "actions":[]

cerulean crypt
#

Thanks

cerulean crypt
#

I have multiple fun notifications convo that can notifi the players when they pressing bulding ...

I want to use the similar notifications convo for other building...

My question is can i make similar convo for multiple building, but they have specific results for each building?

How can i do that?

#

Can i use only 1 convo for multiple building but i want defferent results for each,
Should be specific,It is possible?

noble hedge
#

You lookin for ```json
"template":[
"$temp_00",
"$temp_01",
"$temp_02"
]

cerulean crypt
#

If i separate the final fun
How can i connect it on the first line?

Fun
1 convo ⬇️
2 convo ⬇️
3 convo ⬇️

4 final fun ⏫⏫⏫
Output = 🌝🌚🌜

light plinth
#

Define all fun in a single template and then use building checks at x:0

cerulean crypt
#

Thanks

cerulean crypt
#

I dont have any about what im doing 😅

Is this write?

    "id":"$notify_discription_abandoned_tanker_temp",
    "type":"template",    
    "on click fun":
        [{
    "actions":
            [{"type":"performance",
                //im the first 3 message {fun id}
                "id":"$notify_discription_abandoned_tanker"
                //{what should i write here?}
            }]
        }]
    },
light plinth
#

probably

noble hedge
#

formatting kills

cerulean crypt
#

Wth happened ?
Y everything can be burned .

#
                                "condition": 
                                {
                                "type": "date",
                                "min": 0,
                                "max": 365
                                },
                                "actions":[{
                                "type":"burn" ,"id":"$rusty_industry_1"
                                }]
                                }]```
#

I put specific id on it
Y this was happened

noble hedge
#

probably, bcoz of format 😩

light plinth
#

random fun gets executed for any building

#

You'd have to use 2 conditions

noble hedge
#
"condition":{
 "type":"and", // if you wanna satisfy ALL inner conditions 
 "inner":[
  //more condition-type index here
 ]
}
#

your inner would look smth like this

"inner":[
 {"type":"building", "id":"$bldg_id"},
 {"type":"date", "min":int, "max":int}
]
weak mural
cerulean crypt
#

Thanks

light plinth
#

There's a frame action, otherwise there's no dedicated fun action to change index.

#

There's a call action, which, well, calls Lua

nimble sun
rugged burrow
#

Hey how to find id busway

trim remnant
#

Are you making a plugin?

#

If so you create the ID yourself

cerulean crypt
cerulean crypt
#
Type temp
},

{
Type Building 1
"ok fun":[{
                    "actions":[                    {"type":"notify", "id":"gen notification","z":1},                    {"type":"remove","id":"$building01"},                    {"type":"build", "id":"$building1"}
                    ]}]
}
{
Type Building 2
"ok fun":[{
                    "actions":[                    {"type":"notify", "id":"gen notification","z":1},                    {"type":"remove","id":"$building02"},                    {"type":"build", "id":"$building2"}
                    ]}]
}```
#

How do i can connect
General notification template,
For each of building has different have different results. 😅

cerulean crypt
#

I already connect it but they're not changing

rugged burrow
#

Ok

rugged burrow
light plinth
#

You'd check what the current building is and execute specific action accordingly

noble hedge
#

templates only works for the whole "fun":[ ] attr

#
{
 "id":"$temp_text",
 "type":"template",
 "text":"I'm a notif for all"
},
{
 "id":"$notif_00",
 "type":"notification",
 "template":[ "$temp_text"],
 "fun":[ 
  // actions for bldg_00
 ]
},
{
 "id":"$notif_01",
 "type":"notification",
 "template":[ "$temp_text"],
 "fun":[ 
  // actions for bldg_01
 ]
},
{
 "id":"$notif_02",
 "type":"notification",
 "template":[ "$temp_text"],
 "fun":[ 
  // actions for bldg_02
 ]
}
#

That's how I can see this

#

The "fun" tag above can be any fun attr, like random fun, ok fun, and alike

cerulean crypt
#

Fun conditions can triggered separated fun attribute?

For example

Action 👉}

{Hi im seperate fun 1 condition  if 👉✅ my result 🌝}

{Hi im seperate fun 2 condition  if 👉✅ my result 🌚}```
#

How can i do that?

#

Or


{Hi im separate fun 1 if building was remove i build 🌝}

{Hi im separate fun 2 if building was remove i build 🌚}```
#

If any of these 2 are possible
How can i do that?

noble hedge
#
"fun":[
 {
  "condition":{}, // your condition 1
  "actions":[]
 },
 {
  "condition":{}, // second condition
  "actions":[]
 },
 {
  "condition":{}, // and more
  "actions":[]
 }
]
noble hedge
#

"fun":[] works similar like this

if condition then do actions
cerulean crypt
noble hedge
cerulean crypt
noble hedge
cerulean crypt
noble hedge
#

same logic for all

cerulean crypt
#

This json is by lobby

      {
        "actions":[{"type":"frame","code":"$vars_switch_myvar"}]
      }
    ]```
Can someone explain what is use of ``` "code"``` tag?
#

There's any link for documentation?

cerulean crypt
#

Hi can i ask again why it won't work ||"random fun":[ {"condition":{"type":"and","inner":[ {"type":"date","min":0,"max":5}, {"type":"building","id":"$rusty_industry_1"} ]}, "actions":[ {"type":"burn","id":"$rusty_industry_1"} ] }] },||

#

Idk y they're not burning

wet niche
#

Hmmm I have a script, I want to know if it is json, and what it needs

#

{
"id": "farmatodo",
"type": "commercial",
"width": 3,
"height": 3,
"frames": [
{
"bmp": "farmatodo.png"
}
],
"title": "Farmatodo",
"text": "Una farmacia que ofrece una gran variedad de productos y servicios.",
"level": 1,
"price": 10000,
"monthly price": 100,
"influence park": -10,
"influence noise": -10,
"influence pollution": -10
}

This

#

Sorry for the stupidity, but it's just to confirm

noble hedge
#

Looks fine to me

torpid spear
#

its missing the outermost square brackets

wet niche
#

Ok

#

So?

[{
"id": "farmatodo",
"type": "commercial",
"width": 3,
"height": 3,
"frames": [
{
"bmp": "farmatodo.png"
}
],
"title": "Farmatodo",
"text": "Una farmacia que ofrece una gran variedad de productos y servicios.",
"level": 1,
"price": 10000,
"monthly price": 100,
"influence park": -10,
"influence noise": -10,
"influence pollution": -10
}]

torpid spear
#

should be alright

#

although you should really consider using english if you intend to publish it

wet niche
#

Oh thank you, that's right, I had forgotten

native timber
#

Is there a function that allows you to not display a building?

potent jolt
#

theres a "hidden" tag you can use

#

by setting "hidden": true in your json it wont show up in the build menu

noble hedge
#

"hidden":true

native timber
#

No, I mean make it stand on the tile but not display

light plinth
#

frames: [null]

native timber
noble hedge
#

ig you're looking for virtual variables or lua functions

weak mural
#

use upgrade is more simple.

light plinth
#

Drawing animations with Lua

soft salmon
#

😭😭😭

viral ruin
#

😭😭😭

torpid spear
#

stop

#

thanks

zinc isle
#

thats a json, not script

wet niche
#

I'm sorry lol

zinc isle
wet niche
#

OK, thanks a lot

twilit thorn
viral ruin
#

No LUAers?🥺

zinc isle
#

Theres like 5 people that use lua

kindred nest
#

And two chickens

potent jolt
#

its me

light plinth
#

waluigi?

potent jolt
#

no, the chicken using lua

wet niche
#

Hey, does anyone have a json template to make a cable car?

stoic vector
#

lua moment

trim remnant
#

Notice how this channel is for lua and fun. Not json

#

Use the proper channels please

wary pewter
chrome walrus
#

I have a question can someone teach me the JAVA language please?
thanks in advance

noble hedge
#

not json?

zinc isle
chrome walrus
#

ok thanks

potent jolt
#

Although theotown is made in java, plugins cannot use the language

#

thanks pidroid, very cool

viral ruin
#

Pidroid hate everyone
Everyone hate Pidroid

potent jolt
#

so what's the difference between City.move and City.setView

light plinth
#
The setView function is not intended to be perfectly reversible as getView does not take elevation into account. If all you want to do is to scroll the map this future function may be useful to you: https://doc.theotown.com/modules/City.html#move
potent jolt
#

cinematic camera tool is so back

bold jewel
#

What the lua line for building on slopes?

torpid spear
#

what?

#

lua for building on slopes??

bold jewel
#

I made a decoration for slopes

#

My last step is to make it build on slopes

torpid spear
#

and where would you need lua for that?

bold jewel
#

Idk, I ask if there is a specific code in json to make it possible

torpid spear
#

isn't it possible by default

#

it's also as simple as looking at the tags list

bold jewel
#

Thanks Kulche

steel maple
# torpid spear isn't it possible by default

The Tag list doesn’t state that the tag ‘supports slope’ manages the concrete foundation under the deco. A not clear or not relevant description makes everyone bomb the same questions every time. Just remember me a month ago. I asked the same.

torpid spear
#

?????

#

it clearly states that it makes the building "handle slopes on it's own"

steel maple
#

Exactly. ‘Handles on its own’ is a very vague description of what the tag does. It can mean many things. Add the words about triggering the concrete foundation under the tile.

torpid spear
#

you do you, ask lobby

steel maple
#

How?

torpid spear
#

dm, or simply comment under that post

steel maple
potent jolt
#

i think thats a pretty vague and undescriptive addition

#

since it can apply to other situations than just a bridge

native timber
#

I don't understand how to put in this operator the building whose coordinates will be output?

torpid spear
#

what?

#

you pass the building and the function returns it's x position

#

it's as simple as that

native timber
#

how do I tell the script which building coordinates to look for? I don't see any input value on this site.

torpid spear
#

building:getX()

native timber
torpid spear
#

please read the introduction

native timber
native timber
#

i cant get it

torpid spear
#

????

#

you get the building's data and operate on that as a module

native timber
#

how do I find the coordinates of a building by its draft?

potent jolt
torpid spear
#

count the buildings and iterate through them

#

if you have multiple, of course

native timber
# potent jolt use City.getBuilding

I've used this before, but I didn't quite understand what its output is, I just can't run the plugin right now, can you explain what the output of this command would look like?

torpid spear
#

it outputs the coordinates of said building

potent jolt
#
-- let's get the first building of the draft
local x, y = City.getBuilding(1, someDraft)
#

you ought to check if the city contains the building at all using city.countbuildings

potent jolt
#

also, you shouldnt use these functions too often

#

ideally only on entering the city

native timber
#

two variables, I got it, thanks.

native timber
torpid spear
#

sounds like a horrid idea

potent jolt
#

you ought to collect your building on entering the city

torpid spear
#

why would you have to find the building every day?

potent jolt
#

then keep track of any new ones being built using script:event

#

you can just keep the building object around

native timber
#

I need to check if a particular building is within five tiles of a given building, if I don't check this every day, the action being performed simply won't work

potent jolt
#

then track it manually using events

native timber
#

Forgive me for being stupid in this matter, but I have to learn as I go, I can’t do it any other way

potent jolt
#

because im generous

#

here is an example

#
local draft
function script:init()
    draft = Draft.getDraft('somedraft$00')
end

local locations = {}

function script:enterCity()
    -- get all the buildings that already exist in the city
    local count = City.countBuildings(draft)
    for i = 1, count, 1 do
        local x, y = City.getBuildings(i, draft)
        table.insert(locations, { x=x, y=y })
    end
end

function script:event(x, y, _, event)
    if event == Script.EVENT_PLACED then
        table.insert(locations, { x=x, y=y })
    elseif event == Script.EVENT_REMOVED then
        -- find the coordinate pair in the locations table
        for key, location in pairs(locations) do
            if location.x == x and location.y == y then
                locations[key] = nil
                return
            end
        end
    end
end
#

to track the locations of buildings of a certain draft

native timber
#

Bruh

native timber
#

`bdraft = ...;
bsecdraft = ...;
shielddraft = ...;

local function nextDay();
local buildx, buildy = City.getBuilding(1, [...]);
local buildposplusfive = buildx + 5;
local buildposplusthree = buildx + 3;
local buildposplusone = buildx + 1;
local whatbuildisplusfive = City.getBuildingDraft(buildposplusfive);
if whatbuildisplusfive == bsecdraft then
Builder.buildBuilding(shielddraft, buildposplusthree);
Builder.buildBuilding(shielddraft, buildposplusone);
end
end`

#

Works only for x+ coordinate now, but it easy to increase

potent jolt
#

what

#

there is no City.getbuildingdraft function

#

also semicolons are not required

#

and it still uses getbuilding every single day

#

you could just use script:daily

#

and your script will only work if the other building is exactly 5 tiles away

#

i dont get what youre trying to achieve

native timber
weak mural
#

if you only want to build the building near the main building, use fun is enough.

[{
  "on built fun": {
    "condition”: {"type": "buildable", "id": "$id", "x": 5},
    "action": {"type": "build", "id": "$id", "x": 5}
  }
}]```
random hamlet
zinc isle
#

cuteee

random hamlet
#

Figuring out what goes wrong in your code without a debugger is one of the programming experiences ever

potent jolt
#

excessive amounts of print and log will fix that

#

and copious amounts of restarting the game because i turned on strict lua

random hamlet
#

I wonder if is there any copyright free perlin noise code in lua I could borrow

random hamlet
#

I may actually add war in theotown later

#

:trollface:

random hamlet
#

But I'll make it so your city can get nuked with DSA ICBM

potent jolt
#

how hard can perlin noise possibly be

random hamlet
#

Apparently it's relatively not that complicated but I havent understood it or made my own yet

elder glacier
#

maybe you can i can work together and make our own stragery game lol

random hamlet
#

political map

#

for now just messing with flood fill from random pointa

#

oopsie

zinc isle
#

in?

#

looking good simon

random hamlet
#

thanks

random hamlet
zinc isle
#

wowwwwww

#

i love that 😍

stray crater
#

Agreed

random hamlet
#

thanks

#

now I just have to fix runtime error in unknown line and countries being colored black for some reason

stray crater
#

What are you working on exactly? Terrain gen?

zinc isle
stray crater
#

theotown war update confirmed?

#

Ah I gotcha

#

It looks interesting. If it's on android I may pick it up

zinc isle
stray crater
#

Oh

random hamlet
#

I want to try making a thing where you can develop a country

#

With some policies

#

And building cities/mines/factories/etc. Around it (but done via mining)

#

And trading between other countries

#

And war, but I'm not sure how it'll look

#

It may end up very simple

#

But making trading and resources is just a matter of time

random hamlet
#

If I make this plugin it may actually be worth 40 diamond price or something

#

(If I ever finish it I'll still upload it under the price of 30 diamonds)

trim remnant
#

Make it 31

random hamlet
#

I'm not that evil

#

It's either 30 or at least 35

shell pawn
#

Hell yeah waiting for this bomb plugin

random hamlet
#

some color changes

#

@potent jolt do you know how to track clicks (just clicks)

#

I need to add the ability to select tiles

potent jolt
#

it works inside a tool

random hamlet
#

didnt think about x,y part and thought its only for tiles

#

thanks

potent jolt
#

oh like actual screen coordinates

#

no idea if that works

random hamlet
#

damn

#

these seem to be screen coordinates

#

but idk whats the max value

#

well they stay consistent when I move the map

#

and both increase towards bottom right

#

I hate how screen width and height seem to be a random number

#

and there's no easy way to get canvas x and y (probably there is but I haven't found it yet)

#

ok good

random hamlet
#

maybe canvas/dialog has onClick function or something

potent jolt
#

dang

#

ah yea it do

#

im not sure if the dialog itself has an onclick available

random hamlet
#

well I dont need the dialog itself

#

I need the canvas

#

but dialog could let me make a workaround

potent jolt
#

im not sure if the onclick for a canvas includes the location it was clicked on though

#

youll have to check

random hamlet
#

idk where

#

but if it doesnt it wont be great

potent jolt
#

just try ```lua
local canvas = parent:addCanvas{
onClick = function(self, ...)
Debug.log(Runtime.toJson(arg))
end
}

#

and see if the args contain anything usefull

random hamlet
#

where is the log file btw

potent jolt
#

its in the theotown folder

#

this one

#

the one thats in your userfolder

random hamlet
#

I guess not?

#

now what

#

I guess players will have to type the coordinates

#

unless there's a workaround

potent jolt
#

geuss not

random hamlet
#

why is there no GetMouseX() and GetMouseY()

potent jolt
#

hang on a sec

#

isnt there?

#

i have this

random hamlet
#

I hope there is, but I couldnt find it in docs

potent jolt
#

it should be in my text placing tool somewhere

#

i had it to preview where the mouse is hovering

#

ah

#

i used ```lua
function script:draw(tileX, tileY, hoverX, hoverY)

#

this only works on pc

#

pretty sure this only works while inside a tool though

#

and only the tile coordinates

#

still not what you require

potent jolt
#

think youre gonna have to ask lobby

potent jolt
#

simply put a canvas on every pixel of the screen trol

random hamlet
#

ignore this taking so long for me

random hamlet
# random hamlet

I will add a number grid on the canvas later so it'll be less painful

#

these buttons have the same y value

#

nvm im dumb

#

where tf is my label

#

okay I had to try with constant defined text first

#

I forgot there is no round()

#

I also forgot how lua string joining works

#

I keep typing c++ stuff

#

finally

#

I need to figure out how to add my own icons

#

Im 100% sure its possible

#

(saw in complex industry)

torpid spear
#

aren't icons just animation drafts or something?

random hamlet
#

no idea how it works but no way im figuring it out without seeing an example

#

I guess I have to ask erk

#

kulche were you adding icons in ci, or were you only in charge of drawing them?

torpid spear
#

only the graphics

#

but I've done similar things in the past

#

I think the forum drawing tutorial has what you're looking for

#

the one by bear

random hamlet
#

found this

random hamlet
#

trying to figure it out

#

doesnt work for me for some reason

#

of course it doesnt tell me what exactly is wrong

light plinth
#

what does not work exactly and why

random hamlet
# random hamlet found this

trying to add icons and this is the only example I found, but it doesnt work for me (shows error unless I remove draft.append line)

#

i tried with normal json too but it doesnt work either

#

this also shows an error

weak mural
#

2

#

icons" and icons2" are different. lol