Design Talks - Your Game Module

@carloscosta, very true regarding the double check for “o”. 

This is my “working code” so it’s not optimized and has a lot of artifacts and stand-ins from cobbling together various methods, structures and ideas - some more refined that others.  As for the extra “o” check, sometimes I add a property to the second “o” to add an on-the-fly filter for the objects I’m asking to “die”  see below

[lua]

  1. if (o and o ~= nil) then
  2. – o~= nil is a stand in for testing other properties. While in development I sometimes find in useful to drop in a test another property on the fly like:
  3. if (o and o.x ~= nil) then – sometimes I need to sort objects that way so only some “die”

[/lua]

Also, very true about the double checking for valid arguments.  In an earlier version of the “death” function, all of the instructions were contained in the initial “if” statements.  At some point, I extracted the instruction sets into their own functions (with their own checks) and added a reference without deleting the initial if/then check for valid arguments - so yes, very unnecessary redundancies for now.  This will definitely be refined in a future code revision.  Although now it’s bugging me so I think I’ll do it tonight  :wink:

Carlos, it looks like you are using a database.  What is your preferred method for database integration.  Have you tried / do you use Coronium Core?  It’s worked really well for me.

Only a true coder will do it now rather than defer to another time!  

But that “true coder” should really release something  :wink:

@sporkfin, i’m using a shared hosting plan(reducing costs to min), databases are created in mysql.  database normalization usually is at least 3NF.

To get data from the database to my apps I use webservices created in PHP with prepared statements and some encryption when needed. The best part is after they are created are very easy to use in other apps. most of the changes are the SQL queries, nothing more. 100% of my apps I use local and/or remote databases.

Coronium Core looks fantastic and pretty easy to use, but the running costs of cloud services usually are a bit higher than a shared hosting plan that’s the only reason we went for this approach. Righ now I’m testing Coronium Ace and its really fantastic. in less than a day, learning and creating a small app, i was able to create a small chat app (if i can call it that).

@SGS, working on it bro!   :smiley:

@carloscosta, I’m using digital ocean for $5/month and it easily scales up to meet demand.  With all the cloud server competition and, of course, tech progress in general, DB’s much cheaper than a few years back.

By the way, my new “death” code looks like it got a makeover on a realty TV show for coders   :stuck_out_tongue:

@sporkfin, with $5/month with your plan what can you do or have?

we where paying about 100€/year. we just upgrade our package to a 400 € plan but we only paid half for 2 years (we will negociate the price when the contract is over again). right now we have more than 15 databases. 10 websites some backoffices, “unlimited bandwidth”, “unlimited space”.

By the way, my new “death” code looks like it got a makeover on a realty TV show for coders    :stuck_out_tongue:

LOL. show us :slight_smile:

@sporkfin glad to hear!   Do checkout one.com I was using them until I became a pain and was maxing out their servers (going dedicated was expensive but refreshing).  Their basic hosting is seriously cheap!  I was running 500,000 users on like $100 a year.

I now have dedicated servers for my games at around $100 a month with full redundancy, node replication, unlimited dbs, unlimited traffic, etc.

@sporkfin, i notice that you call a function more than 1 time to clean the same type of object.

what i do is:

i put all timers in a table called timers

i put all transitions in a table called trans

i put all objects in group, or subgroups when needed.

to remove them is less code, easier to debug and prevent errors.

you just need a for i=#timers, -1 do…code inside to remove…end

all timers removed…same for the others.

to remove a scene i only use 1 line: ui.removeMost(masterGroup)

@carloscosta, Yes I do have master lists for all of those and one line control for pausing, resuming, cleansing timers and transitions, and scrubbing entire scenes.  For instance, ui:skillScene() - removes all of the above

The code above was originally referenced as an example of how I cleanse one object when it dies and remove it’s reference from master lists.  The code was an excerpt from a larger section of even crazier code.  I chose to share the snippet I did because it’s the most human readable in that it uses simple names instead of abbreviations from my imagination.  The objects might be the same type, but they have many other objects and events associated with them that also have to be cleansed so it’s not just a simple timer removal until the very last step.

In my world, each object has it’s own AI loop which interacts with other objects and AI loops and physics and timers with delays so when an object dies it might be interacting with a dozen other objects and be in the middle of multiple physics events.  It might also be under the influence of several timers with delays.  Each one of the attributes of the object that dies might be having interactions with other attributes of other objects.  If one object dies and another object is still “thinking” of any aspect of it, I get crashes and memory leaks, so I’m constantly making checks, scrubbing an cleansing hundreds of objects.

I also have to track whether an object is alive so I don’t try to kill it twice.   If an object is dying slowly from say hunger and poison and then something else kills it right before it was going to die, I might end up in a situation where one object dies 3 times in the same millisecond while it’s also interacting with delayed timers.  Actually, before I can even call the “death” function I have to run a “pre-Death” function to unlink the object from other objects and events (basically, tell everyone else to ignore the object). Thus, my code ends up with a lot of redundancies to guard against unanticipated and novels events.  The creatures I’ve been describing don’t move along a path or a grid, in fact, the whole system is very open ended and unpredictable which means - yes, even more if/then checks - so many that they may not even seem abnormal until someone points them out to me  :wink:

Eventually, I circle through the code and cull as many conditional statements as possible - and then I think of another AI enhancement and they return!

@SGS

With numbers like that, I can see how one.com would be appealing with their unlimited bandwidth.

Here’s what the Digital Ocean prices look like.   I still have shared server space on pair.com from back when I was a web designer /developer.  I have found both Digital Ocean and pair.com to have excellent customer service which I prioritize as I don’t get all geeked out happy about server-side work and will pay a premium to not have to worry about it.  That might change when I’ve got hundreds of thousands of users. . . like some people!

So far, I’ve gotten no responses which is… disappointing.  However, maybe I posted this on a bad day for view.

I’m really curious to hear what other folks think and do.  

Please respond if you have any interest in this topic, something to contribute, and the time to do so.  Just five minutes should do it.

Thanks!

My games do not really follow a start, stop, restart format so mine are structured somewhat different.

I have a single scene (you could call this the game module) and show all other scenes via showOverlay() so I have no scene management and refreshing to really worry about.  In my main scene I only have UI/UX, onFrame(), onKey() and onTouch().

Now things get more complicated…  I then instantiate 2D arrays of modules to build my world.  Each module is completely self-contained and only exposes an interface so that the UI can use it.  Otherwise they are responsible for their full lifetime.

I then have lots of helper modules for things like networking, IAPs, translations, z buffer, texture/asset managers, static maps, sounds, particle effects, shaders and various vehicle managers.

Not sure if this was what you were asking for or not?

@SGS - Thanks for the answer.  That was perfectly fine.  

Your game architecture seems more like a spider (for lack of a better analogy) with the main scene being the body and the legs being all the modules/helpers.

Very interesting.

My game is base on a few levels of init.

init the game

   init a party

      init a level

 when my game is finish if the user restart the level it’s reload only the level, if he go to the next level it’s init again party and level… Like this there is no loading

The rest of the module don’t work vertically (play,pause, replay…) they work independently 

I have functions who manage the time. (remove visual effect if under a number of fps etc)

I have a module who manage timer, transition, enterframe (to pause them, x2,x0.5, synchronise when there is hundred of them, resume, finish…)

I have a module who manage sound (to don’t have too much sound play at the same time and too loud)

Manage visual effect (filter when you lose life, use spell, particules for blood and dust)

A module with ML who adapt the level to the player in real time.

Something to manage object in 3D isometric.

Function who manage texture memory (release when there is a warning), load on demand and on the availability of the device

So to elaborate a bit more…  I try and maintain an OOP approach.

For example, I have building.lua which is approx 4k lines of code and this completely handles an instance of a tile/building. 

This will expose properties and functions so that the main scene can manipulate it, functions like selectBuilding(), moveBuildingTo(), removeBuilding(), drawBackground(), etc. 

I can then define my world as buildings[x][y] = <instance of building.lua>

This makes the actual UI coding straightforward.  So if I want to add a road at 13,5 I simply call buildings[x][y]:addRoad().  In that function is all the logic for spawning a road and linking it up with neighbouring roads.

Woah, time to refactor :wink:

Haha, in the Corona version of my game I had modules 10,000 lines long which became a nightmare to debug - now I’m working in Unity I become queasy any time a class goes over 250 lines!

But surely most of that is just pointless squiggly brackets?  :lol:

RG,

  1. am experienced game developer - longtime corona.

  2. yes … always like to use a game module similar to how yours is defined. Mine is just not as elaborate as yours.

I have broke from using a game module a time or two, but I always prefer to use some version of a game module.

  1. I always call versions of create() & init() from my composer scene:create and scene:show … but I will normally have several functions handling all the create stuff, like  ‘createBoard’, ‘createPlayer’, ‘createUI’, etc…  It then depends on what I need done by init() as to wether it is called from scene:show or scene:create.  I don’t call it init(), call it different things depending the game. 

  2. n/a  I use a game module.

  3. I do like to break down the action of the gameScene into regular common actions, common to most games…  like you do, I am just not disciplined enough to do it consistently.  But I am working on making myself a template with some of the same function breakouts as you list them, and hope to stat using them consistently.  I have ‘classes or modules’ that I use for menus, messages,  and effects - those regular and repeated things used in most apps/games. These help keep my gameScene from getting to large.

My general app layout is usually close to this

main.lua  ( handles all the data setup and services(ads, backend, multiplayer) )

gameServer.lua ( module to handle multiplayer stuff )

constants.lua ( global module for constants and standard things like screen dims that are used repeatedly throughout that app )

mainScene.lua ( main menu - each menu item will call a scene or overlay )

setupScene.lua(  customize choices of game play for player - avatar selection, game speed,  etc…)

gameScene.lua ( all game mechanics and action )

then I have a few standard overlay templates I use for help-info, options, credits, game promos etc…

  1. I like this discussion. It is good to see how others tackle these common situations. There seems endless ways to do most things.

Thanks for posting the topic!

Bob

I tend to miss out so much on forums lately. Glad you posted this also to the Slack channel.

I’m developing games professionally for 7 years(6 of it is with Corona) now so I guess you can call me experienced.

  • For casual games, I use a single gameLevel.lua file(a Composer scene actually) and fit all the related functions in this single file. Since it doesn’t get cluttered so much when developing casual games, I still prefer this approach.

  • For point & click adventure games I did in the past, I was using that gameLevel.lua file to call another file where there are many functions like loadLevel(), createLayers() etc. Looking back, it doesn’t seem necessary and probably could have done it like the casual games I make today but that’s what I did for those games. By the way, that file I called for functions was somewhere near 6k lines of code so :slight_smile:

I can’t say I got a naming standart like yours since I’m the sole developer for all my projects but I have something similar to yours. I prefer using a createX(), destroyX(), moveX(), endGame() kind of naming scheme for the games I make. When I need to fix or add some stuff, I search for those keywords(create, destroy, move, end) in the code.

This is not some concept I got from somewhere but the way I come to terms after developing many games. This is working as expected for the casual games at the moment but I don’t know if things will change if I dive into a relatively bigger game.

I would really love to see more discussions like this here which means I have to keep following the forums more often. :slight_smile:

@bgmadclown

 You can have the forums email you all updates immediately like I do. :)    Then you’ll never miss out.

Other than the topics I follow, that would be too much for me :stuck_out_tongue: