Button with 3+ states? How? is movieclip the best way?

Hello guys.

I am trying to make a button have multiple states for an option screen (i.e.: say a button that user use to select sound… mute, sound Fx only and music + Fx) So that button could be used to set the game sound to 3 different state. So far (and maybe it is the best way) is to use movieClip.lua and manage the states myself.

Again it is probably the best way to manage a buttons with more than 2 states but i was wondering if they were alternative to movieclip and if was possible to use ui.lua for this (I doubt it since i think it has only 2 states…)

Anyway, just curious what you guys think.

Thanks.

Mo [import]uid: 49236 topic_id: 20298 reply_id: 320298[/import]

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…:wink:

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]

Thanks sharp1959! It is very cool of you to share. That’s sound like something I can use.

I will report here. I appreciate it.

Mohamed. [import]uid: 49236 topic_id: 20298 reply_id: 79337[/import]