problem with delta time, and a few other questions

  1.  I’m calculating delta time for use in my animations.  I notice randomly i get a spike in dt causing my player to fall through the floor.  it happens after a minute or two if i dont touch the screen. I’m sure this is the cause because I’m printing it when it’s greater than 0.1.  this is my method of calculating dt

    local dt = 0 local lastUpdate = 0 function getDeltaTime() if lastUpdate == 0 then dt = 0 else dt = (system.getTimer( ) - lastUpdate) / 1000 end lastUpdate = system.getTimer( ) end

any idea why there are huge spikes in dt?

  1.  I’m using Dusk which is a great library.   I add it to my project like so.  

    local dusk = require “Dusk.Dusk”

right now the dusk folder is sitting in the root of my project.  i wanted to sitck it in a lib folder.  i try including it this way

local dusk = require "lib/Dusk.Dusk"

or this way

local dusk = require "lib.Dusk.Dusk"

with the first way it says these files must be included using a “.”  and in the second method it says

module ‘Dusk.dusk_core.core’ not found:

i’d figure this would be pretty straightforward,not sure what im doing wrong.

  1.  my third question is about accessing variables from the scene in an outside class.  for example, lets say i create a “Player” file with all the functionality related to my player.  I add the player in game.lua, and I want to call a function from my “game.lua” file within “player.lua”  whats the best way to reach those functions or varaiables?

nobody?

  1.  your device is probably going to sleep, so next delta when it wakes is huge (current time upon wake - last  time prior to sleep)

  2.  it probably loads parts of itself with hardcoded paths, so either edit its source or leave it installed as recommended

  3.  give player a reference to the game object (assumed), then it can access game’s methods/properties, tho not module locals.  (i’d look to restructure elsewhere tho and avoid the need entirely)

  1.  it seems to go to sleep very quickly.  any way to keep the app alive unless otherwise suspended?

  2.  okay thanks for the advice :slight_smile:

  3.  can you explain this a little more?  what is the game object?  is this an object that i add in to keep a reference of all the important stuff within my composer scene? 

  1. setIdleTimer() - use with extreme discretion

  2. there is no game object unless your code creates it.  you talked about classes, but there’s nearly infinite ways you might have structured your code, so i can’t possibly know what your “game.lua” or “player.lua” exposes, but in short:  for code in one module to call code in another module it needs a reference to the thing that contains the other code.

fe if game.lua returns a “singleton” table, then maybe all you need in player.lua is local game=require(“game”) - now player can access game’s properties/methods.  if game.lua returns a class, and you need access to a specific instance, then “whoever” created the instance needs to pass it to player, fe:

--scene.lua local composer = require("composer") local scene = composer.newScene() local Game = require("game") local game = Game:new() local Player = require("player") local player = player:new() player:setGame(game) -- store a reference to the game instance within player for later use -- or maybe you want: player:setScene(scene) -- store a reference to the SCENE instance in player, now player can access SCENE's stuff -- or etc

or any of a million variations on that theme.

nobody?

  1.  your device is probably going to sleep, so next delta when it wakes is huge (current time upon wake - last  time prior to sleep)

  2.  it probably loads parts of itself with hardcoded paths, so either edit its source or leave it installed as recommended

  3.  give player a reference to the game object (assumed), then it can access game’s methods/properties, tho not module locals.  (i’d look to restructure elsewhere tho and avoid the need entirely)

  1.  it seems to go to sleep very quickly.  any way to keep the app alive unless otherwise suspended?

  2.  okay thanks for the advice :slight_smile:

  3.  can you explain this a little more?  what is the game object?  is this an object that i add in to keep a reference of all the important stuff within my composer scene? 

  1. setIdleTimer() - use with extreme discretion

  2. there is no game object unless your code creates it.  you talked about classes, but there’s nearly infinite ways you might have structured your code, so i can’t possibly know what your “game.lua” or “player.lua” exposes, but in short:  for code in one module to call code in another module it needs a reference to the thing that contains the other code.

fe if game.lua returns a “singleton” table, then maybe all you need in player.lua is local game=require(“game”) - now player can access game’s properties/methods.  if game.lua returns a class, and you need access to a specific instance, then “whoever” created the instance needs to pass it to player, fe:

--scene.lua local composer = require("composer") local scene = composer.newScene() local Game = require("game") local game = Game:new() local Player = require("player") local player = player:new() player:setGame(game) -- store a reference to the game instance within player for later use -- or maybe you want: player:setScene(scene) -- store a reference to the SCENE instance in player, now player can access SCENE's stuff -- or etc

or any of a million variations on that theme.