[Resolved] Single Button Multiple States/Functionality

Is it possible to have a single object with multiple states or functionality
for instance I have a Tarot card on screen when I touch it the first time I want it to fill the left hand side of the screen via a transition (landscape mode) on the right a card description appears using a scrollview group. No problems so far. but I want to be able to click on the same card and bring up a menu which allows you to change the text on the right.

I have tried removing the event listener once the card is in place and replacing it with a new listener but having real problems with errors.

[lua]function BigCard2 ()
if bigcard1 == true then
card:removeEventListener (“touch”, movecard)
card:addEventListener ( “touch”, MenuAppear )
State = function MenuAppear
print (“Big Card = True”)
else
card:removeEventListener (“touch”, MenuAppear)
card:addEventListener ( “touch”, movecard )
– State = function movecard
print (“Big Card = False”)
end
end[/lua]

I’m sure there is a better/simpler way of doing this.

I don’t want to toggle the functionality I just want 2 states (or more if need be) and be able to choose when that functionality changes.

State 1: Transition card
State 2: Call Menu

Many thanks for any help to this noob!
[import]uid: 142733 topic_id: 25477 reply_id: 325477[/import]

I’d have something like this;

[lua]local buttonState = 1

local function pressButton(event)
if buttonState == 1 then
–do something here
elseif buttonState == 2 then
–do something else here
elseif buttonState == 3 then
–do a third thing here
end
end[/lua]

That way you can easily change buttonState in the rest of your code to change how the button behaves when pressed.

Does that kind of make sense? :slight_smile:

Peach [import]uid: 52491 topic_id: 25477 reply_id: 103047[/import]

Made perfect sense!
Thanks Peach, That shaved a lot off my program and kept my hair intact too! [import]uid: 142733 topic_id: 25477 reply_id: 103099[/import]

Fantastic :slight_smile:

Marking as resolved. [import]uid: 52491 topic_id: 25477 reply_id: 103242[/import]