How do I move this turret using a slider?

Did I add it right?

Hello?

hi,

Adding a touch eventListener is extremely well documented in numerous tutorials on this site, so no need for me to repeat it here, but here it goes anyway:

It should be something like

slider:addEventlistener("touch", sliderTouched)

Note the use of double brackets, not single brackets.

This code adds a touch eventListener to the image object slider that calls a function called sliderTouched. You are of course free to name your function something else.

The put a print statement somewhere in your touch-eventListener function somewhere so you can check where things work or go wrong like this:

local function sliderTouched(event) if event.phase == "began" then print(slider.y) turretBarrel.rotation = 90 + (slider.y - 140)\*0.5 elseif event.phase == "moved" then print(slider.y) turretBarrel.rotation = 90 + (slider.y - 140)\*0.5 end end -- sliderTouched

If I keep clicking on the slider, it prints this into the console:

Copyright (C) 2009-2014  C o r o n a   L a b s   I n c .         Version: 3.0.0         Build: 2014.2511 Platform: GenericAndroidDevice / x64 / 6.2 / AMD Radeon HD 7800 Series / 4.4.132 83 Compatibility Profile Context 14.501.1003.0 / 2014.2511 WARNING: display.setStatusBarMode() not supported in the simulator for GenericAn droidDevice device Warning: h:\stuff\homework\unit 14 event driven programming (using lua & corona sdk)\assignments\shooting game\main.lua:185: o.anchorX is only supported in grap hics 2.0. Your mileage may vary in graphicsCompatibility 1.0 mode Warning: h:\stuff\homework\unit 14 event driven programming (using lua & corona sdk)\assignments\shooting game\main.lua:186: o.anchorY is only supported in grap hics 2.0. Your mileage may vary in graphicsCompatibility 1.0 mode Warning: h:\stuff\homework\unit 14 event driven programming (using lua & corona sdk)\assignments\shooting game\main.lua:196: o:setTextColor() is deprecated. Use  o:setFillColor() instead 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5 169.5

Hmmpf. I feel like we’re going in circles here. Are you just copy/pasting my code without adding anything to it, or are you integrating it with what you want the code to do?

Would it be easier if I shared my screen on Skype or something?  

Sometimes I don’t know where your code needs to be put in because what you write doesn’t have the same functions as what I have.  And my College has dumped us in at the deep end with Lua.

And I put print here:
 

local function onTouch( event ) local t = event.target print(slider.y)

And the Event Listener is further down:
 

slider:addEventListener('touch', onTouch)

Sharing on Skype… Sheesh… I’m sorry, I don’t mean to be rude, but I’m afraid I’m going to leave the rest of the issue in the hands of you and others because I’m putting in way too much time and we’re not really progressing.

I jumped in to help answer a simple question with a simple math formula, but we’re now venturing into questions about implementing touch listeners and code structuring and debugging. I’d love to help, but I would just be repeating information that is already all over the forum. Sorry about that.