Hi, I’ve written a code for make a button and pressed it but it doesn’t work.
I don’t know why ’
Main :
-- Test
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
local x = 200
local y = 200
local h = 50
local w = 100
parameter("x", 50, 1000)
parameter("y", 50, 1000)
parameter("h", 5, 200)
parameter("w", 10, 400)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
setbutton(x,y,w,h)
local push=push(x,y,h,w)
if push == 1 then
print("Button pressed !")
end
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
end
Roundrect :
function setbutton(x,y,h,w)
stroke(216, 119, 44, 255)
rect(x,y,h,w)
end
function push(x,y,h,w)
local tx
local ty
if touch.x== nil then
tx = 0
ty = 0
else
touch.x = tx
touch.y = ty
end
if tx>x and tx<x+w and ty>y and ty<y+h then
return 1
end
end
This code return this error :
error : error : [ string " function setbutton( x,y,h,w) …"] attempt to index global ‘touch’ (a nil value)
Thanks for explain me this error.