Code: Select all
function script:click(10,10)
Debug.toast("click test")
end
Moderators: Scenario Moderators, Plugin Moderators
Code: Select all
function script:click(10,10)
Debug.toast("click test")
end
Code: Select all
{
"id":"$radioo2",
"type":"decoration",
"category":"$0xadg_cat",
"frames":[{"bmp":"radio.png"}],
"width":1,
"height":1,
"title":"lua test",
"text":"hope this works",
"script":"soundplay.lua"
}
It's a part of bigger json file, only it uses that script. Also, 6th line in .lua file is where the "script:click()" is locatedCommanderABab wrote: ↑24 Jun 2020, 19:09Needs [ at the start and ] at the end if that is the complete json.![]()
It should show me a toast, when I'm tapping at something at x:10 and y:10
Code: Select all
function script:click(10,10)
Debug.toast("click test")
end
I've tried entering id of that building, also a name of it, for some reason, but it still doesn't work.CommanderABab wrote: ↑24 Jun 2020, 20:34It might be expecting the id of a building and not coordinates.
Code: Select all
--- Declaring a function
function sum(a, b) -- use variables in here
return a + b
end
Code: Select all
local number = 12 -- declare variable
--- Calling a function
foo(50, number) -- Use values or variables that were declared
--> res0: number = 62
-- Output of foo(50, number) is 62
Code: Select all
function script:tap(tileX, tileY, x, y)
Debug.toast("You tapped: "..x..","..y)
end
Code: Select all
function script:tap(tileX, tileY, x, y)
local name = "TheoTown"
Debug.toast(name.." detected that you tapped: ("..tileX..","..tileY..")")
end
Thank you very much, I forgot about that function parameters in LuaØlsken wrote: ↑25 Jun 2020, 00:28Ah you're getting a little bit confused with how TheoTown uses functions.
You don't put values in script:click(x, y, level) instead you put in variables like x, y, level (a variable is a word that can have a mutateable (changeable) value). The general rule would be when you declare functions (using the function keyword) you use variables in the parameters (round brackets).But when calling (using) a function you use normal values or variables that contain values.Code: Select all
--- Declaring a function function sum(a, b) -- use variables in here return a + b end
The same logic applies when using script:tap(tileX, tileY, x, y) (using tap as it's easier to explain).Code: Select all
local number = 12 -- declare variable --- Calling a function foo(50, number) -- Use values or variables that were declared --> res0: number = 62 -- Output of foo(50, number) is 62
Let's say you had this code:What this would do is that whenever TheoTown detects that the user tapped the screen it would call this function (hence the name "tap"). Then TheoTown gives you information about the tap. That's what's going to be inside the parameters.Code: Select all
function script:tap(tileX, tileY, x, y) Debug.toast("You tapped: "..x..","..y) end
Let's say if you tapped (20, 40) on the screen TheoTown will put those values inside the x, y of the parameter so that you can use it.
This is probably hard to understand by just reading. I think it would be easier to understand by experiments so try this code out and try to figure out how it works.Code: Select all
function script:tap(tileX, tileY, x, y) local name = "TheoTown" Debug.toast(name.." detected that you tapped: ("..tileX..","..tileY..")") end
Code: Select all
script:click(x,y,level) -- this is will detect attached building positions every where on your city.
script:click(10,10,level) -- this is will detect only on x:10 y:10 coordinate on your city, but level will detect to attached building or road position.
script:click(10,y,level) or script:click(x,10,level) -- this is will be like line, just detect 10 on x or y only, but will detect attached building positions on unfilled x or y.
script:click(x+10,y+10,level) -- this is will detect attached building positions + 10. Your building will be x:0 and y:0 then when you click x:10 and y:10, the script will be work. If your building position in your city is x:50 and y:70, so the script will be work on x:60 and y:80. Other calculation will be work, like - * or / depend on where you need coordinates you want to script will work.