Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Level module
Started by jake1987.jj Oct 03 2017 01:28 AM

- - - - -
40 replies to this topic

[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Thanks to both!!

Now I have what I need



[TOPIC: post.html]
#27

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Hi!

 

Sorry if I use an old post but I think it is useless to open it a new one...

 

I have a question I did not think about. 

As I said long ago, I have a lot of modalities in my game. I wonder what the two alternatives are best:

 

1.Create a database containing all the modes, where each table is equivalent to a modality and contains all the levels

 

2.Create a database for each mode, each database has only one table that contains the levels of the modality

 

Of course the end result is the same but I would like to know what is the best choice for performance and speed



[TOPIC: post.html]
#28

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

Databases are designed for two main things:

 

Lots of records and search for the few you need.

Data relationships.

 

If you're just going to be reading in an entire table in memory and accessing the entire table, a database has more overhead than a flat file perhaps stored as a JSON string for easy parsing.

 

Multiple single-table databases seem like even more excessive overhead unless there are some relationships between the data (table of players, table of player moves indexed by an id in the player of tables). Clearly, multiple tables in a single database are less overhead than multiple databases. But again, unless you're using the power of the database to filter data, why not just use flat files?

 

Rob



[TOPIC: post.html]
#29

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Thank you @Rob Miracle

 

But I do not think I understand it yet.I think that explaining my situation better, I hope I can help me to understand you.

 

I have several  files called "mode1.lua", "mode2.lua", "mode3.lua"  ...etc

 

These files return me 1 table with all levels of that modality ( about 30000 lines, in some cases one level takes 1000 lines)

 

At this point, the user selects a mode and then a level. I need to retrieve that level and load it.

 

What is the fastest way to do this? Seeing the amount of data?



[TOPIC: post.html]
#30

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

At the moment I was loading a record in each table for each level as suggested by @Develephant.

But then I remembered the previous question



[TOPIC: post.html]
#31

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

Why not simply have mode1.lua, mode2.lua etc. as .lua files in your project and simply require them when you need them? You can for organizational purposes put them in a folder.

 

And to keep memory under control a bit, you can always un-require the modes you're not using. (I don't have the syntax for that off the top of my head, but it's a couple of lines of code to cause Lua to forget about previously loading that module)

 

Rob



[TOPIC: post.html]
#32

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

It seems a good idea, that's what I had in mind at first.

 

My preoccupation is that loading the whole table of a mode is both expensive and slow. I have no experience about speed and performance for this I ask for advice here, I just want the best way



[TOPIC: post.html]
#33

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

If you have it as one big table, that would be a huge performance hit. But if each mode is its own file, then you're only loading what you need. 



[TOPIC: post.html]
#34

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

I have a table for each mode.

However, this table contains all levels.

Loading them all is so serious if I only nerve one at a time?



[TOPIC: post.html]
#35

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

I'm confused. Do you have multiple .lua files or do you have one .lua file with multiple tables? Or one really big table?

 

Rob



[TOPIC: post.html]
#36

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

I'm sorry if I do not explain it well.

 

I started from the beginning.

 

I have:

 

mode_1.lua

local M = {}

local levels =  {
	--1
	{
		--about 3000 line
	}

	--2
	{
		--about 3000 line
	}

	--etc to 150
	{
		--about 3000 line
	}
}

function M.getLv( num )

	return levels[num]
end

return M

mode_2.lua

local M = {}

local levels =  {
	--1
	{
		--about 3000 line
	}

	--2
	{
		--about 3000 line
	}

	--etc to 150
	{
		--about 3000 line
	}
}

function M.getLv( num )

	return levels[num]
end

return M

.

.

.

.

And I have about 10 modalities but insert a new one at each update

 

To me of course it only serves one level of one mode each time.

 

Now could you advise me the best way for this?

(json, sqlite, keep these modules, or anything else)

 

Thanks again for the support



[TOPIC: post.html]
#37

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

I apologize for the insistence but I do not know who else to turn to me...



[TOPIC: post.html]
#38

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

I'm not sure I have a good answer for you. I think I understand better.

 

SQL seems to make sense for something like this because you could do:

 

SELECT levelData FROM modes WHERE mode = 1 AND level = 1

 

assuming that your database has columns named "mode", "level" and "levelData" and that "levelData" is holding a JSON string that can easily be converted to a Lua table and that your table is called "modes".

 

That way you are using the database to select a limited set of data from your total set.

 

Rob



[TOPIC: post.html]
#39

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Very well!

 

Thank you very much for your time



[TOPIC: post.html]
#40

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Forgive me if I come back here :(

 

It will be the last time!

 

 At the moment save in system.DocumentsDirectory folder  json file like this:

 

mode_1.json

[{
    "unlocked":true,
    "numLevel":1,
    "completato":false
  },{
    "unlocked":true,
    "numLevel":2,
    "completato":false
  },{
    "unlocked":false,
    "numLevel":150,
    "completed":false
}]

(for each mod a file).

 

This is fine or even here is the better sql?

 

I will never stop saying thank you for the help



[TOPIC: post.html]
#41

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

That would be fine too.




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]