#trying to make an efficient way to sort through table

1 messages · Page 1 of 1 (latest)

graceful prairie
#

for a ben 10 game, this is the snippet of codes i think would be relevant to my issue. i'm just looking for a way to sort through the tables without having to manually if everything like yandere sim

lament epochBOT
#

studio** You are now Level 4! **studio

graceful prairie
#

ty mee6

sharp magnet
lament epochBOT
#

studio** You are now Level 5! **studio

graceful prairie
#

or for like moderators

#

but it'll prolly be changed to alienX instead of waybig

sharp magnet
graceful prairie
#

this is in a serverside script

sharp magnet
#

and?

graceful prairie
#

well im just saying

#

im looking for a solution to this table problem

#

cuz

#

this is my first time attempting using tables

graceful prairie
#

yeah i know but how would i do the thing im trying to do

#

i want to be able to press E or Q to shift onto the next string in the table

sharp magnet
#

wait so what is the problem? selecting an alien or the friends check? or both..?

graceful prairie
#

the friends check is completely fine

#

im trying to make a way to shift through the table

#

rn the script moves the selected alien to the last alien in the table

sharp magnet
#

ok so basically you are going to be making a linked list type of structure

graceful prairie
#

yep and how would i do that

sharp magnet
#

have the aliens available on the client side. then have a starting index. whenever the player presses E or Q the index will increase or decrease by 1 and the selected alien will be the one that corresponds to the index. whenever the index moves to either the last or first index of the table, you will get a range error if you decrease/increase it again. thus you can choose whether the user is unable to select any more aliens to the left/right or you can make it so that if they go too far to the left, they will start selecting from the right and vice versa. then they can just use remote to fire to server which alien they want

#

search up linked list if my explanation bad

graceful prairie
#

i think i'd rather keep the table on the server side, idm if it lags i just dont want vulnerabilities with exploits

sharp magnet
#

it wont have exploits. the user will simply dial which alien they want on the client side, then fire the one they want to the server and the server does security checks

graceful prairie
#

fairs

#

what table function would i use to find the alien with the index

graceful prairie
#

thankyou pyro

obtuse topaz
#

table.find will return bool value if found

#

If you need to find value

sharp magnet
obtuse topaz
#

just access it by index

sharp magnet
#

it returns index or nil

graceful prairie
obtuse topaz
#

I see now

#

confusing again

paper plinth
graceful prairie
#

what is the solution this is all so confusing

paper plinth
#

;compile lua lua local t={cat="c"} print(table.find(t,"c")) -- cat

wooden daggerBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:2: attempt to call a nil value (field 'find')
stack traceback:
prog.lua:2: in main chunk
[C]: in ?

graceful prairie
obtuse topaz
#

In table

#

in list-like it's different

obtuse topaz
paper plinth
paper plinth
obtuse topaz
#

In array

#

But in table it searches for key

sharp magnet
# graceful prairie how

you can traverse the table with a function like this: (sorry for shit formatting im on mobile)

local START_INDEX = 1

local function Traverse(T, increment)
local Index = START_INDEX + increment

if t[Index] then return t[Index] end

if Index < 1 then
return table.maxn(t)
else
return t[1]
end

end

(idk if this works i cant test 🙏)

paper plinth
obtuse topaz
#

now it's right

paper plinth
#

i thought it also worked for dicts. good to know thonk

obtuse topaz
#

I think it would be confusing