Use accelerometer in a method that isn't called by an event listener

Hello.

I want to get the accelerometer x.gravity only in a set time in my game (e.g. when I press a button), so I don’t want to have an event listener listening to it all the time.

I want to have something like

local function exampleFunction ()

      if accelerometer.xGravity > exampleValue then

            print(“success”)

     end

end

What do I do??

 thanks!

You need to use the event system and set a variable lastGravity.x to the last value the event handler received.  There is no polling of the values, they only get set when the device detects movement and an event is triggered.

Rob

You need to use the event system and set a variable lastGravity.x to the last value the event handler received.  There is no polling of the values, they only get set when the device detects movement and an event is triggered.

Rob