#Modules

85 messages · Page 1 of 1 (latest)

frosty rivet
#

hi

#

a dictionary is a table with keys inside of it that return needed values

#

that is a dictionary in most basic terms

#

now image this

#

you have a game with an inventory system, each player has their own items. so lets say we have a player and their inventory looks like this

local inventory = {
    ["Gold Bars"] = 4,
    ["Healing Potions"] = 1,
    ["Cups of Coffee"] = 3000
}
#

we can clearly tell that they have 4 gold bars, 1 poition of healing and 3k cups of coffee

#

(dont ask i took this code from roblox api documentation)

#

now lets say that we want our code to know how many gold bars the player has

#

imagine each value in a dictionary as a door and the key as well a key

#

behind each door is our data that we want to use

#

and the key allows us to access said door

#

if we want to access lets say door "Gold Bars" we just use the key "Gold Bars"

#

and we can do that with the square brackets

#

all you need to do is just the name of the dictionary. so in this case inventory, square brackers and inside the brackets the name of the key

#

so the final product that we get is inventory["Gold Bars"]

#

and if we compile it we can see it prints 4

#
local inventory = {
    ["Gold Bars"] = 4,
    ["Healing Potions"] = 1,
    ["Cups of Coffee"] = 3000
}
print(inventory["Gold Bars"])
coral basaltBOT
#
Program Output
4

frosty rivet
#

thats it

#

thats all dictionaries are

#

just arrays that have a key assigned to each value

#

array = table btw

#

just so u wont get confused when i say array

#

if u need any further help with dictionaries i dont mind helping

jagged anvil
frosty rivet
jagged anvil
jagged anvil
#

no idea

#

i just got q dm

#

and i was banned

#

💀

#

ok

frosty rivet
#

hi

#

alright so

#

this function takes a string as its parameter

#

and the table.find searches for the index location in the dictionary of the inputed parameter

#

and if it finds something

#

it knows it can use the inputed parameter to return a value

#

hmm i can quickly check if u want

#

i dont see table.match in the docs

#

i think its something that got deprecated

#

oh you got confused with string.match

#

also just a heads up writing Dictionary.KeyName is the same as writing Dictionary[KeyName]

frosty rivet
#

so pretty much all this function does is it checks if the provided string aka parameter actually exists in the DIfficultySetting table and if it does exist it sets Selected to the needed difficulty that is stored in the dictionary

#

thats it

#

it specifies between all difficulties because you input it the difficulty key name

#

so if i were to input "Easy"

#

it would return me the value of easy

#

which is 0.5

#

oh

#

you are suppose to input a STRING

#

you cant just write Easy

#

you need to do "Easy"

#

the inputed parameter has to be equal to the key

#

yes

#

and if u test it out everything should work

#

just take your time and relax

#

wdym

#

the parameter?

#

default is nil

#

if you write local function thing() it has no parameters

#

so theres nothing being inputed into the function

#

it is

#

both are functions

#

do you know the basics of parameters

#

define them for me

#

close

#

Parameters in simple terms are just data that can be inputed into a function to be used in its functionaltiy

#

in your case the data that you input is a string

frosty rivet
#

because you wrote Difficulty as its parameter?

#

which tells the code theres something that needs to be inputed

#

when you write

local function doThing()
     print("thing!")
end

here there is no inputted parameter which means the code shouldnt expect an input which means if you write

#
doThing("HI!!!")
#

the "HI!!!" will be inputted

#

but it wont be used

#

because you didnt define the parameters name in the functions brackets

#

however if you do

#
local function doThing(TextToPrint)
      print(TextToPrint)
end
#

if you write

#
doThing("HI!!!")
#

the code will use the parameter

#

and its inputted value