Create on/off button in lua script
No need to searching values for every time
Simple script but better ideas
Read this simple script carefully
You will be understand
Specially thanks to @MuhammadRizwan87
Credit @TDOhex
function search()
gg.clearResults()
gg.setRanges(gg.REGION_C_DATA)
gg.searchNumber("1;2;3", gg.TYPE_FLOAT, false, gg.SIGN_EQUAL, 0, -1)
gg.refineNumber("1", gg.TYPE_FLOAT, false, gg.SIGN_EQUAL, 0, -1)
local t = gg.getResults(3)
for i, v in ipairs(t) do
t[i].name = 'testoff'
end
gg.addListItems(t)
gg.clearResults(t)
end
search()
on = "[OFF]"
off = "[ON]"
test = off
function main()
menu = gg.choice({
test.." Test",
"Exit"}, nil, "Example by @TDOhex")
if menu == 1 then
if test == off then
test = on
local t = gg.getListItems(testoff)
for i, v in ipairs(t) do
if v.name == "testoff" then
t[i].value = 0
t[i].name = 'teston'
end
gg.setValues(t)
gg.addListItems(t)
end
else
test = off
local t = gg.getListItems(teston)
for i, v in ipairs(t) do
if v.name == "teston" then
t[i].value = 1
t[i].name = 'testoff'
end
gg.setValues(t)
gg.addListItems(t)
end
end
elseif menu == 2 then
print("Thanks to visiting @TDOhex")
gg.copyText('https://t.me/TDOhex')
intro = "Join to @TDOhex"
for i = 1, #intro do
gg.toast(intro:sub(1, i) .. "_✍")
gg.sleep(140)
end
local t = gg.getListItems()
gg.removeListItems(t)
os.exit()
end
end
while true do
if gg.isVisible() then
gg.setVisible(false)
main()
end
end
I just shared it...
On-Off_Example.lua