local phrases = {"Hello!","How are you?","I love ROBLOX!"} while wait(5) do local phrase = phrases[math.random(1,#phrases)] game:GetService("Chat"):Chat(workspace.PartName,phrase,Enum.ChatColor.White) end**
in the math random was this [], but i would like to ask what it means and how to use them? also {} ()
For example,
phrases[1] will get your phrase AT the position one
local phrases = {"Hello!","How are you?","I love ROBLOX!"} orint(phrases[1])
You could also say the following if you have a dictionary: We're getting the game.Players AT royaltoe the index royaltoe and myDictonary at the index dog
print(game.Players["royaltoe"] --you can do the same for tables if you write your table like this: myDictonary = {door = workspace.Door, dog = workspace.Dog} print(myDictonary ["dog"])
Not much special about this, it just specifies where you want the table to start and to end.
myTable = { "bob", "apple", 2, game.Workspace.Part }
You can make a table inside a table like so:
myTable = { innerTable = {} } print(myTable.innerTable) -- prints the inner table's memory address
or if you don't want to name the table you can do this:
local x = {} -- create a table named 'x' local metaTable = {} -- create a table to store the 'x' table setmetatable(x, metaTable) -- puts the table 'x' inside of the table 'metaTable' print(getmetatable(x)) --print's the table 'x''s memory address --conceptually it looks like this: metaTable = { {} } -- x is inside metatable
Writing the function:
foo = 2 --variable with the same name as the function function foo(parameter1, parameter2) print(parameter1, parameter2) end
Since the variable foo and the function foo have the same name, how are we supposed to tell them apart? We can do that with () to tell the script that we're calling a function. Since foo has parameters we need to make sure we're sending the parameters inside ()
foo = 2 -- changing foo variable foo(1,2) -- calling the function with the parameter --we can also say foo(), but the parameters will be nil since we specified nothing --so it'll print "nil nil"
()
These classic brackets are used in functions. For example:
kill(WindowMall)
{}
These brackets typically enclose an array or class. Example:
local idiots = {“sahadeed”,”sahadeed”,”sahadeed” }
[]
These brackets are used to find a specific item in an array using its position. For dictionaries, the position can even be a string. For normal arrays, numbers only.
local biggestidiot = idiots[math.random(1,#idiots]
Above gets a random position of idiots and makes the chosen the biggest.
Comment for any questions