Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to manage a large amount of sprite sequences and sprite options? Also questions on modules.
Started by domfrank00 Jun 07 2019 11:12 AM

- - - - -
4 replies to this topic

Best Answer nick_sherman , 08 June 2019 - 11:46 AM

This is a simple module:

 

 
-- myModule.lua
 
local m = {}
 
m.moduleVariable = "hello"
 
m.moduleTable = {50, 20, 10}
 
m.moduleFunction = function ()
  print ("I am a function inside a module")
end
 
m.moduleFunctionUsingParams = function (passedObject)
 
  print (passedObject)
 
end
 
m.moduleFunctionThatReturnsSomething = function ()
 
  return "hello once more"
 
end
 
 
return m
 

 

 

And it can be used inside a scene or another module like this:

 

 
local myRequiredModule = require("myModule")
 
 
print (myRequiredModule.moduleVariable)  -- hello
print (myRequiredModule.moduleTable[1]) -- 50
 
myRequiredModule.moduleFunction() -- I am a function inside a module
 
myRequiredModule.moduleFunctionWithParams("hello again") -- hello again
 
print (myRequiredModule.moduleFunctionThatReturnsSomething()) -- hello once more
 
 

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

domfrank00

[GLOBAL: userInfoPane.html]
domfrank00
  • Observer

  • 4 posts
  • Corona SDK

In the current project I'm working on, just while getting basic mechanics down I have a main.lua, playScene.lua and testScene.lua.

 

Currently in main.lua I just enter straight into playScene.lua. 

 

playScene.lua has a button that says 'play' and when pressed goes into testScene.lua. 

 

Both only contain a few lines of code. 

However as soon as I'm in playScene.lua it becomes a mess. I make a LOAD of sprite sequences and sprite options. I declare collision filters, set a speed variable which controls movement speed and all the code controlling the players movement is within this scene. Also all the code which controls shooting.

 

Now what I'm wondering is how I should manage this, obviously there is more in playScene that what I listed but what I listed are things which, to me, could be put inside separate modules.

 

Now questions on modules, say, for example if I were to put my movement function within a module, and then call it with a enterFrame listener would the movement work fully normally? 

Is it possible to store all my sprite sequences and options inside another module?
 

Thanks in advance.



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

Yes you can.  As your project grows you will normally localise related functions into their own modules/classes.



[TOPIC: post.html]
#3

domfrank00

[GLOBAL: userInfoPane.html]
domfrank00
  • Observer

  • 4 posts
  • Corona SDK

Yes you can.  As your project grows you will normally localise related functions into their own modules/classes.

 

I've been trying this and have no idea how to get it work. I put everything to do with movement inside a function in another module, inside that function are another 3 functions that have listeners, however whenever I try to call this I get the error: attempt to index local 'playerMovement' a nil value. playMovement is the variable I use to require. I've been looking at tutorials all day and everything is honestly baffling me. 



[TOPIC: post.html]
#4

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,803 posts
  • Corona SDK

  Best Answer

This is a simple module:

 

 
-- myModule.lua
 
local m = {}
 
m.moduleVariable = "hello"
 
m.moduleTable = {50, 20, 10}
 
m.moduleFunction = function ()
  print ("I am a function inside a module")
end
 
m.moduleFunctionUsingParams = function (passedObject)
 
  print (passedObject)
 
end
 
m.moduleFunctionThatReturnsSomething = function ()
 
  return "hello once more"
 
end
 
 
return m
 

 

 

And it can be used inside a scene or another module like this:

 

 
local myRequiredModule = require("myModule")
 
 
print (myRequiredModule.moduleVariable)  -- hello
print (myRequiredModule.moduleTable[1]) -- 50
 
myRequiredModule.moduleFunction() -- I am a function inside a module
 
myRequiredModule.moduleFunctionWithParams("hello again") -- hello again
 
print (myRequiredModule.moduleFunctionThatReturnsSomething()) -- hello once more
 
 



[TOPIC: post.html]
#5

domfrank00

[GLOBAL: userInfoPane.html]
domfrank00
  • Observer

  • 4 posts
  • Corona SDK

i simply wasnt putting M.whatever before doing things inside the module... thankyou. 




[topic_controls]
[/topic_controls]