#Array Identifier

139 messages · Page 1 of 1 (latest)

tame beacon
#

Hello! i am very much new to the Roblox development scene, my past experiences are JASS (Warcraft 3) which is a language that specializes in arrays and Integer, however what I want to know is that

How does one make a table of arrays in Roblox Studio that refers to the conditions of a player?

for example, in array [1,1] we have the ID of the player, in array [2,1] we have the rank of requirement for something to happen,
what i want to accomplish is how does the LUAU logic work regarding the referral of an array's type of execute a command?

for simple terms, how does one make the code so that it checks the player ID in a table and their rank in the group for a command to be executed, right now im trying to learn arrays pretty much.

crisp heath
#

I don't think I have understood you at all but you may be talking about arrays overall. I don't know what JASS is but here in Lua if you want to check, using arrays only, you would make a dictionary in which the player data is stored

local players = {
  1736716372 = {
    ["RANK"] = "Owner"
  }
}

And then you access its rank by doing players[1736716372]["RANK"]

tame beacon
#

if a player is ranked such and such it would go to a specific array-table

#

for it's ID

#

for example

#

when a player joins --> it's ID would be identified if it meets with the rank scope it is on a table

#

and if it is positive it happens

#

the scope being if it's ID is set on an array for a rank

grand jasper
#
local Table1 = {1, 2, 3, "abcd", 999} -- this is a table
print(Table1[2]) -- 2
print(Table1[4]) -- "abcd"


local Table2 = {
  a = 1,
  b = 2,
  abc = "textextext",
  another_table = {1,2,3}
} -- this is also a table
print(Table2.a) -- 1
print(Table2["b"]) -- 2


local Table3 = {
  1,
  2,
  a = 7,
  lol = "foo",
} -- this is called MIXED TABLE it is also a thing but you should really avoid doing like this
print(Table3[1]) -- 1
print(Table3.a) -- 7
print(Table3["lol"]) -- "foo"
tame beacon
grand jasper
#

yes

tame beacon
#

i assume it still has the same concept

#

are tables in luau dynamic or static

grand jasper
#

tables combine functionality of arrays and dicts

grand jasper
tame beacon
#

for example, tables have a value on rows etc etc

#

can they be changed via a dynamic trigger (a script triggering)

#

or is there like a specific Dynamic table

#

that is a table but can be changed

grand jasper
#

table has Indexes and Values
index can be a number or a string, value can be anything

tame beacon
#

can they be changed mid-way before initialization?

outer pathBOT
#

studio** You are now Level 1! **studio

grand jasper
#

Table[Index] = Value

tame beacon
#

is pretty much my question

tame beacon
grand jasper
#

local Table = {}

Table.a = 999

grand jasper
tame beacon
#

does Table.1.1 means it assigns 1 of the 1st in "Table"

#

or can there only be 1 index

#

in a table

grand jasper
#

you cant do Table.1

tame beacon
#

to simplify it basically

grand jasper
#

dont think of them as 2d

tame beacon
#

so if that's the case i assume i can add an index of an index

#

in Roblox's Table?

#

so that i dont have to make a thousand types of tables if needed be

grand jasper
#
local Table = {}
print(Table[1]) -- nil
Table[1][1] = "something" -- error
tame beacon
#

and if it prints [1][1] it will give "something" as an output

#

correct?

grand jasper
#

yes you can put a table inside of other table and then it will kinda act as if it was 2d

tame beacon
#

sweet

grand jasper
#

look

#

no wait look

tame beacon
#

yep? im lookin

grand jasper
#

if you do print(Table[1][1]) it will error because Table[1] is nil (nothing) and you basically trying yo do print(nil[1]) which gives error

#

however

#

if you do Table[1] = {} beforehand it will not error

#

idk how to explain this propperly

tame beacon
#

oh because the scope is table 1

#

yeah i understand how scope works

#

it basically means you run something under this alias

#

seeing that we run it under table 1

#

it defines that whatever is INSIDE of table 1 that we are about to trigger will be triggered

#

which is [1] inside of [1] to be the output

#

correct?

#

seeing the original one is

#

we run whatever is in the first index of "Table"

grand jasper
#

what are you trying to do

tame beacon
# grand jasper what are you trying to do

right now seeing i want to become a backend programmer im using this table to compile people's name under an index [1] being let's say organizer only for it to verify the player's id that is stored manually in the index

outer pathBOT
#

studio** You are now Level 2! **studio

tame beacon
#

it's a foolproof solution if someone tries ranking some random organizer

#

without going through the developers

#

so that organizers must be put in the data inside of the game and ranked

#

rather than just purely ranked

grand jasper
#

why dont you use data inside the game only?

#

like why do you need group rank if you gonna check data inside the game anyway

tame beacon
#

so you cant really be an organizer without being in the group and the data

#

so if we add someone in the data

#

but they arent in the group (which doesnt trigger the script)

#

then they wont be given organizer ingame

#

so that people can remove their ranks on a whim

#

and people cant add people on organize

#

on a whim

#

it must be verified both ways like a blockchain

#

hence the use of arrays / tables

grand jasper
#

ive made a possible solution but its kinda not easy-to-understand

#

idk

tame beacon
#

ooh hit me with it

grand jasper
#
local GroupId = 0000 -- your group id

local GroupRanks = {
  Owner = 255
  -- Rank Name = Rank id in group
}

local UserRanks = {
  Owner = {
    999999999,
    -- Userids of users in this rank
  }
}

function GetRank(Player)
  for Rank, UserIds in next, UserRanks do
    if table.find(UserIds, Player.UserId) then
      local GroupRank = GroupRanks[Rank] or 0
      return Player:GetRankInGroup(GroupId) >= GroupRank and Rank
    end
  end
end
#

idk

#

maybe its easy for u maybe not

#

so

tame beacon
#

this is actually

#

mind boggling

#

so i dont have to use tables

#

holy cow

grand jasper
#

GroupRanks contains association between group rank ids to rank names

#

255 is group owner

tame beacon
#

i assume the Player in GetRank(Player) refers to every individual player

grand jasper
#

when you call GetRank(Player) it returns rank name or nil

tame beacon
#

the rank name of the player or the rank name of?

grand jasper
#
game.Players.PlayerAdded:Connect(function(NewPlayer)
  local Rank = GetRank(NewPlayer)
  print(`Player {NewPlayer.Name} with rank {Rank} has joined!`)
end)
tame beacon
#

ah this is what i was wondering for

grand jasper
#

so there may be mitakes

#

idk

tame beacon
#

oh yeah no dont worry man :D
im here to ask on what the stuff is

#

so far i have a great gist on what you are saying right now which is good seeing to be fair

#

i think it's stupid for me to ask here for someone to make me a whole script and just copy paste it in studio :]

#

so right now thanks to you i actually know about tables in luau

tame beacon
#

is GroupRanks it's own variable / string?

#

because i see local behind it

grand jasper
#

for example you want to add new rank called "Head Admin"
in your group corresponding rank has id = 254
and you want 3 players with userids of 111111, 222222 and 33333 to have it

  1. in GroupRanks you specify required group rank id:
local GroupRanks = {
  Owner = 255,
  ["Head Admin"] = 254
}
  1. you add the users to UserRanks:
local UserRanks = {
  Owner = {
    999999999
  },
  ["Head Admin"] = {
    111111,
    222222,
    33333
  }
}

done! that should work. now GetRank will return "Head Admin" if one of those 3 players join and if he have 254 or higher group rank

#

if player has group rank but not on the UserRanks table -> GetRank will return nil
if player is in the UserRanks table but does not have group rank -> GetRank will return nil

tame beacon
#

why does the head admin ahve brackets

#

and not owner

#

cant they all have brackets

grand jasper
#

beacuse there is a space

#

you cant do Head Admin = "something"

tame beacon
#

AH because there's more than 1 inside of Head Admin

#

then what about

local GroupRanks = {
Owner = 255,
["Head Admin"] = 254
}

grand jasper
#

you sent the same table

tame beacon
#

oh it's the same table i thought it's different because its GroupRanks

#

not UserRanks

#

i was copying that table because if i look at that one which is GroupRanks

#

it has no value other than the id

#

so cant i do Head Admin = 223

grand jasper
#
local GroupRanks = {
  ["Owner"] = 255, -- this will also work
  ["Head Admin"] = 254
}
tame beacon
#

oo

grand jasper
tame beacon
outer pathBOT
#

studio** You are now Level 3! **studio

grand jasper
#

same table cant have 2 identical indexes (keys)

tame beacon
#

local GroupRanks = {
Owner = 255,
Head Admin = 254
}

grand jasper
#

you cant

#

if the key contains spaces then you should enclose in [""]

tame beacon
#

ah i see

#

well seeing i can use brackets on all

#

it would look clean

#

Thanks man! @grand jasper appriciate it man

grand jasper
#

youre welcome, I hope my code helps