Corona remote: problem

Hi,

I have Corona Remote and I am trying to control a ball with it. It will connect, but it does not seem to be working.
Here it is:

local physics = require("physics")  
physics.start()  
physics.setGravity(0, 0)  
  
local ball = display.newImage("ball.png")  
ball.x = 100  
ball.y = 100  
physics.addBody(ball, { bounce = 0.4, radius = 30} )  
  
local motionx = 0  
local motiony = 0  
   
local function onAccelerate(event)  
motionx = 15 \* event.xGravity  
motiony = 15 \* event.yGravity  
end  
Runtime:addEventListener("accelerometer", onAccelerate)  
   
local function moveBall(event)  
ball.x = ball.x - motionx  
ball.y = ball.y - motiony  
end  
Runtime:addEventListener("enterFrame", moveBall)  
  
-- Load The Remote  
local remote = require("remote")  
  
-- Start The Remote On Port 8080  
-- "fast" Network Speed ( or "slow" )  
remote.startServer( "8080" , "fast" )  
  
-- Get The Latest Accelerometer Values  
local function updateAccelerometer()  
 xGravity = remote.xGravity  
 yGravity = remote.yGravity  
 zGravity = remote.zGravity  
 xInstant = remote.xInstant  
 yInstant = remote.yInstant  
 zInstant = remote.zInstant  
 isShake = remote.isShake  
 -- Only Use If Compass Activated and running v1.1  
 magnetic = remote.magnetic  
end  
  
-- Add Enter Frame Listener  
Runtime:addEventListener( "enterFrame" , updateAccelerometer )  

Thanks in advance!
[import]uid: 15281 topic_id: 5689 reply_id: 305689[/import]

Try put everything below “-- Load the remote” first. Maybe it tries to control the ball before connection and that screws it up [import]uid: 30185 topic_id: 5689 reply_id: 19576[/import]

Try this code:

[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0)

local ball = display.newImage(“ball.png”)
ball.x = 100
ball.y = 100
physics.addBody(ball, { bounce = 0.4, radius = 30} )

local motionx = 0
local motiony = 0

local function moveBall(event)
ball.x = ball.x - motionx
ball.y = ball.y - motiony
end

Runtime:addEventListener(“enterFrame”, moveBall)

–[[ either load the accelerometer
local function onAccelerate(event)
motionx = 15 * event.xGravity
motiony = 15 * event.yGravity
end

Runtime:addEventListener(“accelerometer”, onAccelerate)
–]]

—[[ or load the remote
local remote = require(“remote”)

– Start The Remote On Port 8080
– “fast” Network Speed ( or “slow” )
remote.startServer( “8080” , “fast” )

– since you are using either the accelerometer or the remote
– make this function work same as your onAccelerate function
– but with remote.xGravity instead of event.xGravity etc.
local function updateAccelerometer()
motionx = 15 * remote.xGravity
motiony = 15 * remote.yGravity
end

– Add Enter Frame Listener
Runtime:addEventListener( “enterFrame” , updateAccelerometer )
–]][/lua]

The problem you have is that you need to use either the accelerometer or the remote, but not both. Also, the event listener you are using for the remote (updateAccelerometer) is not doing anything with the data it is getting passed. You are just assigning the remote’s data to some variables. What you want is to make your updateAccelerometer function work like your onAccelerate function. I gave an example of this above.

Also, I left the code for the normal accelerometer commented out so it will not interfere with your remote code. If you want to deploy to an actual device add an extra dash “-” to the beginning of the line [lua]"–[[either load the accelerometer"[/lua] to uncomment the accelerometer code. Also remove the extra dash from the line [lua]"—[[or load the remote"[/lua] to comment out the remote code.

[import]uid: 16410 topic_id: 5689 reply_id: 19777[/import]

I made the remote. I didnt see this post as the remote has a dedicated forum under the 3rd party tools.

If you are still having trouble drop me an email at support@coronaremote.com

Matt

BTW remote.lua will provide real accelerometer data when running on a device, on the simulator (it does the checking) it listens for a tcp connection from the iPhone Remote App.

To solve the above issues you need to do this.

-- Load The Remote  
local remote = require("remote")  
   
-- Start The Remote On Port 8080  
-- "fast" Network Speed ( or "slow" )  
remote.startServer( "8080" , "fast" )  
  
local physics = require("physics")  
physics.start()  
physics.setGravity(0, 0)  
   
local ball = display.newImage("ball.png")  
ball.x = 100  
ball.y = 100  
physics.addBody(ball, { bounce = 0.4, radius = 30} )  
   
local motionx = 0  
local motiony = 0  
   
local function onAccelerate(event)  
motionx = 15 \* remote.xGravity  
motiony = 15 \* remote.yGravity  
end  
Runtime:addEventListener("enterFrame" onAccelerate)  
   
local function moveBall(event)  
ball.x = ball.x - motionx  
ball.y = ball.y - motiony  
end  
Runtime:addEventListener("enterFrame", moveBall)  

What you do is replace the accelerometer listener with an enter frame listener and instead of asking for event.xGravity you ask for remote.xGravity

Have fun!

Matt

[import]uid: 5354 topic_id: 5689 reply_id: 20420[/import]

Thanks,

This resolved my issues.

Joyful

ps This is a great tool! [import]uid: 15281 topic_id: 5689 reply_id: 20503[/import]