native.showAlert and buttons

Dear Corona Developers,

I have been trying to add three buttons, purchase, restore and cancel, in my alert.

Unfortunately, I haven’t got any luck so far.


Corona Simulator Runtime error:

File: …esktop/Corona New Book Template JP IAP/pagescene.lua

Line: 40

Attempt to index global ‘restore’ (a nil value)


A friend of mine told me there is something wrong with my code. 

Could anyone here show me how to correct it? (He told me my lua language is not correct… )

Thank you so much.

Henry 

local function onComplete( event )

    if “clicked” == event.action then

           local i = event.index

        if 1 == i then

                – Do nothing; dialog will simply dismiss

        elseif 2 == i then         

                restore:addEventlistener(“top”,payitem.restore)

                end

        elseif 3 == i then

        purchase:addEventListener(“tap”, payitem.payIt)

    end

end

Hi,

Try this code.

local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then -- Do nothing; dialog will simply dismiss elseif 2 == i then -- call Purchase function here elseif 3 == i then -- call Restore function here end end end -- Show alert with three buttons local alert = native.showAlert( "Alert", "Please Click a Button", { "Cancel", "Purchase", "Restore" }, onComplete )

Good Luck!

burhan

Thank you so much Mr Burhan J.

What do you mean by “-- call Restore function here”?

I have amended my code according to your suggestion, but the app turned funny.

Please advise me.

Regards,

Henry

My latest code:

Hi Burhan

Sorry, I tried again.

It works perfectly well now.

Thank you Burhan.

Thank you so much for your kind help.

Regards,

Henry

Hi,

Try this code.

local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then -- Do nothing; dialog will simply dismiss elseif 2 == i then -- call Purchase function here elseif 3 == i then -- call Restore function here end end end -- Show alert with three buttons local alert = native.showAlert( "Alert", "Please Click a Button", { "Cancel", "Purchase", "Restore" }, onComplete )

Good Luck!

burhan

Thank you so much Mr Burhan J.

What do you mean by “-- call Restore function here”?

I have amended my code according to your suggestion, but the app turned funny.

Please advise me.

Regards,

Henry

My latest code:

Hi Burhan

Sorry, I tried again.

It works perfectly well now.

Thank you Burhan.

Thank you so much for your kind help.

Regards,

Henry