How do I make a working spinwheel app that can be changed? Any help will be greatly appreciated!

Hello, I am trying to work on how to make a spin wheel, like the one on http://wheeldecide.com that is changeable and works functionally. I have tried multiple different methods and scripts to try to give off the desired payoff.

local spin = display.newImage ("spinwheel3.jpg") spin.x = 315 spin.y = 575 local adjustment = 0 local spinWheel = display.newImageRect( "wheel.png", 250, 250 ) wheel.x, wheel.y = display.contentCenterX, display.contentCenterY local function onTouch(event) display.getCurrentStage():setFocus( event.target ) if(event.phase == "began") then local dx = event.x - (spinWheel.x) local dy = event.y - (spinWheel.y) adjustment = math.atan2(dy,dx) \* 180 / math.pi - spinWheel.rotation elseif(event.phase == "moved") then local dx = event.x - spinWheel.x local dy = event.y - spinWheel.y wheel.rotation = (math.atan2(dy,dx) \* 180 / math.pi) - adjustment end end wheel:addEventListener('touch', onTouch) 

Nothing has really worked except adding a background. I have tried for a long time, and this will be my first app. Can anyone provide any help?

Don’t see anything wrong there. What’s the problem or desired output ?

Well, when I click run, all it displays is the background but with the corona loading icon on it, and stating that there was something wrong with line 8.  The payoff is supposed to be a wheel, that when you click, spins around. Any help?

If you can paste the error here, that would go a long way towards obtaining assistance.

My error is this:

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

File:main.lua

Line:8

stack traceback:

            main.lua:8:  in main chunk

I have now changed my code to this:

local spin = display.newImage ("spinwheel3.jpg") spin.x = 315 spin.y = 575 local adjustment = 0 local spinWheel = display.newImageRect( "wheel.png", 250, 250 ) local function onTouch(event) display.getCurrentStage():setFocus( event.target ) if(event.phase == "began") then local dx = event.x - (wheel.x) local dy = event.y - (wheel.y) adjustment = math.atan2(dy,dx) \* 180 / math.pi - spinWheel.rotation elseif(event.phase == "moved") then local dx = event.x - wheel.x local dy = event.y - wheel.y wheel.rotation = (math.atan2(dy,dx) \* 180 / math.pi) - adjustment end end wheel:addEventListener('touch', onTouch)

but now it says that “wheel:addEventListener” is a (nil) value and everything it said before

I assume you want to use “spinWheel” and not “wheel”. Remember to check your variables as they need to be the same when assigning listeners and other attributes.

Ah, yes. I realized that after I posted and still the same error

Well, line 8 is blank above, so I can’t imagine this is the code that is throwing the error. You might want to delete lines 6-8 and re-enter the object manually.

That is the updated version, i meant for the updated version line 20, so I will try retyping it, thanks

ERROR: Runtime error

                    /Users/(My full name)/Desktop/main.lua:65: attempt to index global ‘scene’ (a nil value)

                    stack traceback:

                    /Users/(My full name)/Desktop/main.lua:65: in main chunk

I don’t see anything referencing “scene” in the above code.

I’m going to assume that the only code you have is what was posted in your other forum thread. In your particular case, it looks like you copied a small snippet of a Composer scene, without the rest of the related listeners to actually get it to run correctly. Please note, blindly copying and pasting code that was found on the internet or even other Corona forums posts will rarely result in a solution.

I strongly suggest boiling down your project to the absolute bare bones. Get the images to show up. Ensure that you can attach listeners to them which print out data about the images. Check for the different phases of a touch listener on those images. Below is the Getting Started guide for Corona; it will walk you through a lot of these concepts.

https://coronalabs.com/resources/tutorials/getting-started-with-corona/

Don’t see anything wrong there. What’s the problem or desired output ?

Well, when I click run, all it displays is the background but with the corona loading icon on it, and stating that there was something wrong with line 8.  The payoff is supposed to be a wheel, that when you click, spins around. Any help?

If you can paste the error here, that would go a long way towards obtaining assistance.

My error is this:

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

File:main.lua

Line:8

stack traceback:

            main.lua:8:  in main chunk

I have now changed my code to this:

local spin = display.newImage ("spinwheel3.jpg") spin.x = 315 spin.y = 575 local adjustment = 0 local spinWheel = display.newImageRect( "wheel.png", 250, 250 ) local function onTouch(event) display.getCurrentStage():setFocus( event.target ) if(event.phase == "began") then local dx = event.x - (wheel.x) local dy = event.y - (wheel.y) adjustment = math.atan2(dy,dx) \* 180 / math.pi - spinWheel.rotation elseif(event.phase == "moved") then local dx = event.x - wheel.x local dy = event.y - wheel.y wheel.rotation = (math.atan2(dy,dx) \* 180 / math.pi) - adjustment end end wheel:addEventListener('touch', onTouch)

but now it says that “wheel:addEventListener” is a (nil) value and everything it said before

I assume you want to use “spinWheel” and not “wheel”. Remember to check your variables as they need to be the same when assigning listeners and other attributes.

Ah, yes. I realized that after I posted and still the same error

Well, line 8 is blank above, so I can’t imagine this is the code that is throwing the error. You might want to delete lines 6-8 and re-enter the object manually.

That is the updated version, i meant for the updated version line 20, so I will try retyping it, thanks

ERROR: Runtime error

                    /Users/(My full name)/Desktop/main.lua:65: attempt to index global ‘scene’ (a nil value)

                    stack traceback:

                    /Users/(My full name)/Desktop/main.lua:65: in main chunk