corona - attempt to index global 'physics' (a nil value) -


i'm new corona/lua , i'm can't find solution thing. i'm trying spawn object fall top down , should stop @ bottom of screen. i'll create touch event etc etc..

but problem recieve error:

attempt index global 'physics' (a nil value)

and objects ofc doesn't fall down.

here code:

----------------------------------------------------------------------------------------- -- -- main.lua -- -----------------------------------------------------------------------------------------  local buttony = display.contentwidth * 0.02 local buttonwidth = display.contentwidth * 0.1 local buttonheight = display.contentwidth * 0.1  background = display.newimage("graphics/background.jpg")  local localgroup = display.newgroup() local spawntable = {}  function spawnlattina(params)     local object = display.newimage(params.image, params.buttonx,50);     object.objtable = params.objtable;     object.index = #object.objtable+1;     object.name = "object:".. object.index;       --fisica     if params.hasbody          object.density = params.density or 0;         object.friction = params.friction or 0;         object.bounce = params.bounce or 0;         object.issensor = params.issensor or false;         object.bodytype = params.bodytype or "dynamic";         print(object.density .. " friction: ".. object.friction .."bodytype: "..object.bodytype)          physics.addbody(object, object.bodytype,                  {density = object.density,                  friction = object.friction,                  bounce = object.bounce}         )      end      object.group = params.group or nil     object.group:insert(object)     object.objtable[object.index] = object       return object end  = 1, 2     local spawns = spawnlattina(         {             image = "graphics/lattina.png",             objtable = spawntable,             buttonx = math.random(50,480),             hasbody = true,             density = 0,             friction = 12,             bodytype = "static",             group = localgroup,         }     ) end 

you haven't started physics engine. write following lines on top of class:

local physics = require "physics" physics.start() 

keep coding.................. :)


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -