SOLVED: See the last couple of posts for explanation for similar issues. Good Day!
Hi,
This will look like a lot but the code is easy to follow. So please bare with me. ^-^
I’m getting some strange errors when my level restarts by death but not by restart button.
I am using the Director class, and i created several groups.
This is the top of my level .lua file
module(..., package.seeall);
function new()
local localGroup = display.newGroup();
-- Create ui display group. (to follow the player but not be scrolled around)
local ui = display.newGroup();
-- Create master display group. (for global "camera" scrolling effect)
local game = display.newGroup();
game.x = 0;
game.y = 0;
Because my camera scrolls i seperate my images into the different groups.
I think this bit is VITAL, game.x and game.y is the whole level except the UI. (because that shouldn’t scroll)
My restart code is this:
function restartScene()
Runtime:removeEventListener( "enterFrame", move );
Runtime:removeEventListener( "enterFrame", moveCamera );
Runtime:removeEventListener( "enterFrame", boundreset );
Runtime:removeEventListener( "enterFrame", Cinematic );
cancelAllTimers();
cancelAllTransitions();
audio.play(btnpress);
physics.start();
director:changeScene(e.target.scene,"fade", "white");
package.loaded["W1-2"] = nil
\_G["W1-2"] = nil
return true
end
If I die, I call the restart function to restart the level.
I recieve an error even though the restart scene is the same as the button’s restartScene.
(Maybe because i call it from a timer or collision?)
"
Runtime Error
attempt to compare number with nil value,
…
.lua:706"
This leads me to a function boundreset()
This function checks the game.x and game.y (director group)
for camera scroll.
function boundreset
local function boundreset()
if (game.x \> 0) then
game.x = 0;
--return true
end
if (game.x \< -480) then
game.x = -480;
--return true
end
if (game.y \> 0) then
game.y = 0;
--return true
end
if (game.y \< -320) then
game.y = -320;
--return true
end
end
It would seem it can no longer read the game.x and game.y. (They are nil? :s)
I would like to repeat if I press a button I created to call the restartScene, it does the exact same thing and has no problem with game.x and game.y, it simply resets them back to 0 , 0 (At the start of the file) and the level starts anew.
I’d appreciate brainstorming here i suppose.
Is there something that could cause this from calling from a timer or collision?
Am I nil’ing the game.x and game.y in some way that prevents them getting reset to 0, 0 when the level restarts?
Thanks for your consideration.
Yours Sincerely
Matt. [import]uid: 91798 topic_id: 17148 reply_id: 317148[/import]
[import]uid: 3826 topic_id: 17148 reply_id: 64551[/import]
[import]uid: 52491 topic_id: 17148 reply_id: 64581[/import]