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?
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.
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.
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’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.
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
}
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