How to split a Lime project into modules?

I’ve been working and learning about how organize my code into modules, now that I started learning about Lime I ran into some questions about that topic.

Right now I’m at the “mario” tutorial with animating a player. If I would make a module for the player, how would I do that?

Is that possible so I can reuse the player code or do I have to write the player code for each and every level and make the player in every tilemap I create?

I’ve always loved Lime(s)…
David [import]uid: 34126 topic_id: 11051 reply_id: 311051[/import]

You can use modules in a Lime project in much the same way you would in any other Corona or Lua project.

In your case you could make a Player class ( module ) that would have all the player logic such as movement, lives, weapons, animations etc and then you could use something like an objectListener to initiate that Player object somewhere in your map. [import]uid: 5833 topic_id: 11051 reply_id: 40215[/import]

Its pretty easy to do as well. When i was making my game i threw all the player logic into a module, and it worked great. I ended up just leaving it with each level though because i was already so far along i would have had to rewrite some other code, and just left it with each level. [import]uid: 39391 topic_id: 11051 reply_id: 40272[/import]

I have put almost all player logic in the player module.

When it comes to player animations, I tried pulling them out of my spritesheet and it works fine, I also tried it with lime and it works fine too. But what is the best way to that, should I make all animations from spritesheet or make them through Lime?

So, I have no problems creating them I just wonder what is the best way to reuse the player logic?

from what I have read in the forums, lot’s of modules doesn’t affect the performance and I like to keep my project in smaller modules since it is easier to find and edit stuff that way.

I’m using director class too.

[import]uid: 34126 topic_id: 11051 reply_id: 40643[/import]

When I was adding in the animated tiles I only ever really expected them to be used for small things, for example maybe you wanted a flickering light or some moving grass etc. I probably shouldn’t have shown them for characters first however I was getting so many emails about that I had to do a tutorial.

Personally what I what do is for things like a player or enemy I would have their animation code in their own module however if you did want it in a tileset remember that once you have set it up you can turn the tileset into an external tileset, that way you don’t have to recreate it for each level you can simply import it and you’re good to go.
[import]uid: 5833 topic_id: 11051 reply_id: 40645[/import]

Need help about this, I make a player module, but I don’t hnow how to initialize without losing my module reference…

local \_player = require ("player")  
local player = \_player.init()  
local onPlayerProperty = function(property, type, object)  
 player = object.sprite  
 player:first\_run() -- Error, is not a module anymore  
end  
map:addPropertyListener("IsPlayer", onPlayerProperty)  

[import]uid: 45670 topic_id: 11051 reply_id: 49667[/import]

At the top you have initialised your object and assigned it to a variable named “player”, I am going to assume that has initialised how you expected and is all working fine. Then in your object listener function you reassign that player variable to the object.sprite variable which means that it is no longer your initialised module which is why your next line doesn’t work.

You will want some function in your player module that can take the visual part of the object and assign it to your player object, that way in your object listener you could do something like this:

  
player:setVisual( object.sprite )  
player:first\_run() -- Error, is not a module anymore  
  

Without knowing the inner workings of your module I don’t know how that new function would be set up, but that should point you in the right direction.
[import]uid: 5833 topic_id: 11051 reply_id: 49702[/import]