Which is faster for storing data: Tables or Object Values?

Which is faster for storing data Tables or Object Values?

I’m currently making a Bomberman-inspired game and I want to create multiple types of bombs with different abilities. I want to be able to make it so each bomb does different things based on which bomb it is. Per example, the basic bomb will have a blast radius of 3 tiles in all directions and the superbomb will have a blast radius of 6 tiles in all directions + diagonals.

Currently, I’m planning on just placing a bunch of Object values. Like the boolvalues,numvalues,stringvalues, etc. that you can add inside an object. This way I can use a script to read from the bomb library I have in ServerStorage.

But I have a feeling that having a dictionary or table of these values could be faster. And it would mean I wouldn’t have a bunch of values underneath the bomb model. That way it wouldn’t replicate the values into workspace when I clone it.

To restate the question; which is faster? a table/dictionary made in a script for each bomb, or placing object values inside each bomb?

1 Like

Unless you’re having hundreds of bombs nor performance nor speed should be a factor. I personally like dictionaries more, they feel more organized - but you can keep it organized with values within folders.

It’s really up to you I’d say.

2 Likes

Table and Object Values are way different, Object Values are just for Instances while Tables can contain all type of data. I recommend using Tables. As @AvionicScript said: I personally like dictionaries more, they feel more organized.
Same with me.

EDIT: What are you storing in that ValueBase?

1 Like

Inside each bomb will be at least these values with the value type:

BlastRadius (In Tiles): NumVal
BlastDamage (How many hearts it takes): NumVal
CanExplodeCrates: BoolVal
CanExplodeUnbreakables: BoolVal
FuseTime: NumVal

So mainly numbers and true/false statements.

Yeah, I think you should use tables, they are really good. I also think they have better performance than an UserData. It also depends on your use case. If you plan to have many scripts accessing those variables and is easy for you to use the ValueBases then do it. Else, if is just one script the one handling the bomb use a Table.

I think you’d be better with a dictionary. Maybe store in a ModuleScript from easy access anywhere on the game.

1 Like

Even with multiple scripts, a ModuleScript should get the job done.

1 Like

You are right, but idk if he knows about scripting with modules. In case he knows, then yeah he should use modules.

I’m just using one single script in ServerScriptService that categorizes and copies each bomb into the game based on player input from a remote event. So I think as it’s one script a dictionary will work great while keeping the actual workspace less cluttered with values.

I don’t know that much about lua dictionaries so this will be a nice time to learn about them. Thank you.

1 Like

There’s the dev hub link for ModuleScripts here

Just put the table in the script and then on the other script

local bombInfo = require(moduleScript path)
1 Like

then just use it as a normal table

1 Like

You will find they’re super easy to use and incredibly useful.
Think of them as organized tables, instead of doing myArray[2] to get if it’s equipped or not just do myArray.Equipped

Difference in code

local myArray = {2,false}
local myDictionary = {
   ["Can Explode"] = true,
   Equipped = false
}

This might come in handy

2 Likes

I’ve never used modules before, my understanding is that I would have to place

local bombInfo = require(moduleScript path)

at the top of my bomb handler
and each bomb will have its own module script inside it with a dictionary describing its settings?

Perhaps… explain it to him?

Everyone on this forum is here to learn in some way and I am sure that OP would love to expand his scripting knowledge to incorporate module scripts (if he doesn’t know how to already).

No need to evade a genuine solution because it would take a bit more effort to write a reply about it.

You can do that or just one dictionary in one module script.

So it would be like

local module = {}
module.BombInfo = {
   ["Small Bomb"] = {
     Radius = 4,
     etc,
   },
 ["Medium Bomb"] = {
     Radius = 10,
     etc,
   }
}
return module

--- then the script to get the bomb info

local bombInfo = require(game.Workspace.ModuleScript).BombInfo -- use this in as many scripts as you need
2 Likes

I haven’t used modulescripts in a while but I think this is how it works

To avoid clutter in your code you could take a route that looks more like this:

return {
   ["Small Bomb"] = {
     Radius = 4,
     etc,
   },
 ["Medium Bomb"] = {
     Radius = 10,
     etc,
   }
}

And the server script side of things:

local bombInfo = require(workspace.ModuleScript)

Avoids having to arbitrarily define a table and a table member and looks cleaner overall.

1 Like

Yes, I think this will work quite efficiently and should save me time when it comes to changing object values in each model.

Thank you for giving me more insight into how dictionaries and module scripts work and I believe I would be apt to catalog settings this way.

In case he needs to add another type of object like idk BulletInfo, he will need the first case.