Ending object.

Hi,
I am completely new to corona.
This is my “level_1.lua” code:

module(..., package.seeall)  
  
function newlevel\_1 ()  
 local super = require("\_level\_1")  
 local this = super:newlevel\_1()  
  
-- Load level  
local level = require("level")  
  
 return this  
end  

I want to load “level” scene on top of my “level_1”. This code does not work. How would I do this?
Do I need to “end” the “load level”? Do I have the “load level” in the right place?

Thanks in advance.
– [import]uid: 15281 topic_id: 6419 reply_id: 306419[/import]

What do you mean by “on top of”? [import]uid: 12108 topic_id: 6419 reply_id: 22203[/import]

Hey
You mean that you want to switch the scene from one “screen” to another “screen” by loading a new level or scene and placing it on top of the current scene.

You should look and download the director class which is just wonderful for doing stuff like this. Just remember to end all objects between changeScene otherwise you will get some weird errors.

Also take a look at the Ghosts VS Monsters demoapp which is using director class. [import]uid: 22737 topic_id: 6419 reply_id: 22207[/import]

Thanks for the replies.
What I mean is opposed to wrighing certain things that are in every level over and over.
You use a “level.lua” file (it has your background (if that does not change) maybe your walls ect.).
So I guess I am tiring to “import” (I know this is the wrong word!) the contains of the “level.lua” file.
My code I had in the earlier post does not work, do I have to end the “load level” or something?

Thanks
– [import]uid: 15281 topic_id: 6419 reply_id: 22219[/import]

http://developer.anscamobile.com/code/object-oriented-sample-game-framework

The thing to notice is how every level uses the same boundary walls and that’s only written once in one place, while the background image changes. [import]uid: 12108 topic_id: 6419 reply_id: 22224[/import]

Hi,

I see what your saying, but why do I get a not see “level” with this code:

module(..., package.seeall)  
local level = require("level")  
  
function newlevel\_1 ()  
 local super = require("\_level\_1")  
 local this = super:newlevel\_1()  
  
 return this  
end  

Thanks [import]uid: 15281 topic_id: 6419 reply_id: 22228[/import]

None of the code in level.lua runs until you call those functions. Simply requiring a lua module doesn’t cause it to run.

Moreover, your little code snippet there is pretty confusing without any context. Don’t just show us what’s in level_1.lua, also post code from level.lua and _level_1.lua

And for that matter post the code that calls newlevel_1() in level_1.lua because while I would assume that’s being called from main.lua I can’t tell what’s going on.

Oh and I would imagine super:newlevel_1() is generating errors; when you get errors you should really tell us about them. The colon operator is used to call functions in tables and since “super” isn’t a table then that command doesn’t make any sense.


More generally, actually read the code from that link I posted. It does what you are asking, so read it to figure out how it works. [import]uid: 12108 topic_id: 6419 reply_id: 22231[/import]

Ok, sorry I was a bit confusing, this is my first game.
Let’s say I have a file called “ball.lua” in it there is basically just a ball image with shadow ect.
Now, I have a file called “level_1”. how can I simple “insert” this “ball.lua” into my game level?
I have looked at yours, is this were you call for the “level” file?

--constructor--------------------  
function new(func) --menu button function  
 local obj = display.newGroup()  
 Level.decorate(obj)  

– [import]uid: 15281 topic_id: 6419 reply_id: 22246[/import]

There are actually two spots, and that’s one. The decorate() function attaches all the methods of the “level” module to that specific level. However decorate() still doesn’t draw anything, and I still need to call the other methods. One of the methods from the “level” module is setupWalls() and when I call that a little later then it builds the outer walls. [import]uid: 12108 topic_id: 6419 reply_id: 22247[/import]

Is this were you “setup the walls”?

obj:setup\_walls() [import]uid: 15281 topic_id: 6419 reply_id: 22276[/import]

Assuming you are looking in level1.lua then yeah. In level.lua that’s the function declaration, that’s not actually calling the function. The function is declared in level.lua and then it is used in the various levels. That’s the entire point; declare once, use everywhere. [import]uid: 12108 topic_id: 6419 reply_id: 22280[/import]