#about tables
1 messages · Page 1 of 1 (latest)
for storing multiple values
im kind of just trying to start up some discussion to get some coding help
okay cool
so how i could use it is for seperate unique blocks
so like
dirt block
mining time = 0.5
steel block
mining time = 10
for example you want to make a shop system so for the shop it needs a value inside
return {
["Sword"] = {
["Cost"] = 15,
["Description"] = "Good for close range combat :)"
},
} then you can use this value to make a template so you dont have to add a template one by one because it will automatically create a template by how many is in your table.. 🙂
i used table a lot so its only my experience
When working with tables, there are two different variants.
Arrays, which are stored values whos keys are paired numbers:
{1 = true, 2 = false, 3 = 10, ...}
Dictionaries, which @young iron was showing you, are values that have the index as a "key". These keys can be almost anything
{["Cost"] = 15, {"Descriiption"] = "HELLO"}
It just takes experience to use tables tbh
The more you use them, the more uses you find for them
You can use modules to just store data like this
not only it can be used for OOP Structure xd
Or use them as a lobby system which stores players in the lobby and other types of data
I wasn't trying to get into that for thenm since they seems pretty new
okay so tables would be useless for what im trying to code
i want this system (and any future ones) to be applied to any future blocks i make
just like this one
But yeah @young iron is right, you can use metatables to replicate OOP
im aware about arrays and dictionaries but its nice to get a reminder
OOP?
Object Oriented Programming
It's a programming structure to create recreatatble objects
For example, a animal class (apart of oop) can create an animal based off of criteria that you add
class is a blueprint where you can create multiple object by using a blue print and using that object you can use the method inside of the object or even use the methods of a blue print 🙂 that's how i interpreted it 🙂
methods is like an action by the way
local AnimalClass = {}
AnimalClass.__index = AnimalClass --Metatable stuff
type animal = ... --Custom Class Type
function AnimalClass.new(AnimalName: string, attributes: {}): animal
local self = setmetatable({}, AnimalClass)
...
return self
end
tbh I'm kinda lazy to finish this
hey idk what is type, export does?
This is how most people interpret OOP, all it is, is making a blueprint for an object you want to make and using that object for other stuff
export type just exports it outside of a module
So you can use that type for other scripts
wait how do i use export type tho.. outside of a module?
can you givem e some example
Nah just export type ...
And if you require that module that had the exported type
you can call that type inside the new script
idk how type annotation works aswell because i only understand it only accept specific value like name: string
local TestClass = require(...)
type Animal = TestClass.animal
okay how exactly could i make the little hoverbox system (when curser goes over block an outline appears) apply to any block in my game and any block named differently?
ive made it so it only works for the specific block ive made as of now
i feel like what i learn from this will be very useful for alot of things about code in the future (im a noob so im trying to learn all the different things and how i can apply them as game mechanics)
you can store in in module script if i were you 🙂 and use it in your gui
like this one 🙂 i dont want a long script inside of a local script that's why i added a module script to make less code in the future.
just did some reading on module scripts
YOU CAN USE CODE IN MODULE SCRIPTS FOR OTHER SCRIPTS
my near code inept mind is blown
its the answer to alot of my problems
you can organize your scripts using module script 🙂
i think that's my only purpose of using module script
@static bolt If you know how return's work, then modules should make perfect sense
You can only get data from a module that has been returned
i think to get into level 2 scripting i need to learn the best practices for um namings, and other stuff that improves readability of code right?
i still half understand return statements, even when its been explained to me i cant understand, "returns it?"... returns it to what?
i've used return statements im pretty sure but i dont understand how it works, is it just any yellow text like ":Connect()"?
if you call a function and it has return then if you called that function it will return something
return n1 + n2
end
print(add(1,2))```
returning can either return some form of data OR stop the code there
idk if anyone will still be able to help with this but is there something about the mouse hover statements that are broken, because sometimes when i stop having the mouse hover, the outline on the block remains.
also when i made it play a sound it plays the sound a whole lot even though it in the middle of hovering, I'm assuming these bugs are happening because the game identifies my mouse as hovering over it multiple times (even if its already over the block).
you see it around the end of the video
i think i will repost this on a new post
ignore this i guess
Make a check in the code
For the last instance that was hovered over