Hello lemsim,
I dug this up off the hard drive that I put together, to do
some switching in my game / programs…with a little bit
of a mod or two it might do something for ya…maybe using
a table / array was what I was thinking…but have not tried
anything yet…good luck
have fun…
Willow Road games
Larry
[code]
– Plug n Play and modify to suit your situation / code requirements
–Based on SIMPLE LUA SWITCH FUNCTION by Nexus Game Studio (09/30/11)
–Has been modified by Willow Road games 1/11/2012
– ******************************************************************
W = display.contentWidth; H = display.contentHeight
–Displays a yellow circle above the button. This is a light.
local light1 = display.newCircle(50,50,50)
light1:setFillColor(255,255,0)
light1.x = W / 2 - 50; light1.y = H / 4
light1.isVisible = false; --if you want it to be on initially, set to true or false
light1.onOff = false; --monitor the state of the light on or off? (true / false)
–the isVisible and onOff varibles should be set the SAME
local light2 = display.newCircle(50,50,50)
light2:setFillColor(255,255,0)
light2.x = W / 2 + 50; light2.y = H / 4
light2.isVisible = true;
light2.onOff = true;
local light3 = display.newCircle(50,50,50)
light3:setFillColor(255,175,175);
light3.x = W / 2 + 150; light3.y = H / 4;
light3.isVisible = false;
light3.onOff = false;
–Tap function that detects when the user has touched a switch
local function toggle(event)
event.target.switchit.isVisible = not event.target.switchit.isVisible
if event.target.switchit.onOff == true then
event.target.switchit.onOff = false;
elseif event.target.switchit.isVisible == true then
event.target.switchit.onOff = true;
end
– print the state of the light switch in debug mode, comment out for final compile
print("\nSwitch Status: ", event.target.switchit.onOff);
print("Switch IsVisible: ", event.target.switchit.isVisible);
end
–Displays a little square on screen to indicate a light switch / or load a .png or .jpg file
local button1 = display.newRect (50,50,50,50)
button1:setFillColor(255,0,0)
button1.x = W / 2 - 50; button1.y = H / 2
button1.switchit = light1
button1:addEventListener( ‘tap’, toggle)
local button2 = display.newRect (50,50,50,50)
button2:setFillColor(255,0,255)
button2.x = W / 2 + 50; button2.y = H / 2
button2.switchit = light2
button2:addEventListener( ‘tap’, toggle)
local button3 = display.newRect(50,50,50,50)
button3:setFillColor(240,240,0);
button3.x = W / 2 + 150; button3.y = H / 2;
button3.switchit = light3;
button3:addEventListener(‘tap’, toggle);
– end of line
– *********************************************************** [import]uid: 107633 topic_id: 20298 reply_id: 79324[/import]