Is this supported in Android on Windows?
I can't get around the following error:
Runtime error
C:\Users\Chris\Desktop\droidPop\main.lua:76: bad argument #2 to 'mRand'
(interval is empty)
stack traceback:
[C]: ?
[C]: in function 'mRand'
C:\Users\Chris\Desktop\droidPop\main.lua:76: in function '_listener'
?: in function <?:441>
?:
-------------------Code snip---------
mRand = math.random;
----Here is line 76
droids.x = mRand(50, _W-50); droids.y = mRand(-20, _H-870)
"Is this supported in Android on Windows?" Yes! :)
droids.y: the second parameter is smaller than the first.
droids.y = mRand(-20, _H-870)
_H - 870 <-- This is the problem.
I am just learning the Corona stuff: So learning some. I was going through examples and found that line that I could use. I change the numbers and still I get the error.. Thanks in advance. What values would make it work?
local function spawndroid()
local droid = display.newImageRect("droid.png", 72, 88);
droid:setReferencePoint(display.CenterReferencePoint);
droid.x = mRand(50, _W-50); droid.y = mRand(20, _H-10);
physics.addBody(droid, {density=0.1, friction=0.1, bounce=0.1, radius = 9})
I think it should work:
(for example: draws on the screen five droids random places)
local _W = display.contentWidth
local _H = display.contentHeight
mRand = math.random
local function spawndroid()
local droid = display.newImageRect("droid.png", 72, 88);
droid:setReferencePoint(display.CenterReferencePoint);
droid.x = mRand(50, _W-50); droid.y = mRand(20, _H-10);
end
for i = 1, 5 do
spawndroid()
end
Thanks and yes it worked that got me looking that at what was worng with my code: All works great until I add the function droid:touch(e)
I think part of the issue I am having is coding in 'notepad' and Getting my code mixed up between java and vb
One minute they work and the next they don't --- I know user error---
--> Physics
local physics = require("physics")
physics.start()
physics.setGravity( 0, 1) -- .01 m/s*s in the positive x direction
physics.setScale(200) -- 200 pixels per meter
--local sky = display.newImage("bg2.png")
local ground = display.newImage("ground.png", true)
ground.y = display.contentHeight - ground.contentHeight/2
physics.addBody( ground, "static", { friction = 1.0, bounce = 0, density = 1.0 })
--Constants for the level
o = 0;
time_remain = 10;
time_up = false;
total_droids = 20;
ready = false;
_W = display.contentWidth
_H = display.contentHeight
mRand = math.random
local function trackDroid(obj)
obj:removeSelf();
end
local function spawndroid()
local droid = display.newImageRect("droid.png", 55, 55);
droid:setReferencePoint(display.CenterReferencePoint);
droid.x = mRand(50, _W-50); droid.y = mRand(20, _H-10);
--physics.addBody(droid, {density=0.1, friction=0.1, bounce=0.1, radius = 9})
function droid:touch(e)
if(e.phase == "ended") then
--Remove the droid
trackDroid(self);
end
end
droid:addEventListener("touch, droid");
end
tmr = timer.performWithDelay(20, spawndroid, total_droids);
This code works:.... Notepad :) I had " in the wrong place... Any way to step through code?
--> Physics
local physics = require("physics")
physics.start()
physics.setGravity( 0, 1) -- .01 m/s*s in the positive x direction
physics.setScale(200) -- 200 pixels per meter
--local sky = display.newImage("bg2.png")
local ground = display.newImage("ground.png", true)
ground.y = display.contentHeight - ground.contentHeight/2
physics.addBody( ground, "static", { friction = 1.0, bounce = 0, density = 1.0 })
--Constants for the level
o = 0;
time_remain = 10;
time_up = false;
total_droids = 20;
ready = false;
_W = display.contentWidth
_H = display.contentHeight
mRand = math.random
local function trackDroid(obj)
obj:removeSelf();
end
local function spawndroid()
local droid = display.newImageRect("droid.png", 55, 55);
droid:setReferencePoint(display.CenterReferencePoint);
droid.x = mRand(50, _W-50); droid.y = mRand(20, _H-10);
--physics.addBody(droid, {density=0.1, friction=0.1, bounce=0.1, radius = 9})
function droid:touch(e)
if(e.phase == "ended") then
--Remove the droid
trackDroid(self);
end
return true;
end
droid:addEventListener( "touch", droid );
end
tmr = timer.performWithDelay(20, spawndroid, total_droids);