@sim @john - I know there will be a simple explanation for this but I can’t see why this code fires an error up. It’s basically written to capture orientation change. It fires an error up as it is posted but if you rem out the aspect call in function update(dt) then the code works fine. I’m sure I’ve used this in the past without problem.
viewer.mode = FULLSCREEN
function setup()
--
init()
end
function update(dt)
--
aspect = checkAspect()
end
function draw()
--
update(DeltaTime)
background(0)
if aspect > 1 then
-- landscape
pushStyle()
fill(255, 14, 0)
font("AmericanTypewriter-Bold")
fontSize(32)
textMode(CENTER)
text("Please switch to Portrait Mode", cW, cH)
popStyle()
else
-- portrait
end
end
function touched(touch)
--
t = touch
if t.state == BEGAN then
end
end
function init()
--
aspect = WIDTH/HEIGHT
sW, sH, cW, cH = WIDTH, HEIGHT, WIDTH//2, HEIGHT//2
end
function checkAspect()
--
local check = WIDTH/HEIGHT
local asp
if check ~= aspect then
asp = WIDTH//HEIGHT
sW, sH, cW, cH = WIDTH ,HEIGHT, WIDTH//2, HEIGHT//2
end
return asp
end
Edit : The only explanation I can give is that Update() is run before init() - is that the case?
Edit2: I think I know what it is, in the checkAspect()
function the aspect derived is an integer so it’s neither greater or less than one. Will check up when I get chance on my iPad.
Edit3: Modified to obtain a real for asp and it still throws out an error.