#What does index mean in Lua programming language

49 messages · Page 1 of 1 (latest)

stray sphinx
#

I'm new in the lua programming language and scripting in roblox studio i need clarification on what this means the microsoft edge doesnt give me good answers so i was hoping to get good answers here.

valid garnet
#

think of it like this

#
local Index = {"1", "2", "3"}
print(Index[3])
#

i dont know how else

#

to give a good example

prime lanceBOT
#

studio** You are now Level 6! **studio

stray sphinx
#

from this

thorn jungle
#

yes it does

stray sphinx
#

okay thanks

stray sphinx
valid garnet
#

ah

umbral gyro
#

The index is like the key to access a certain value inside of an array, for example, we have this array

local prices = {3, 9, 5, 20, 15}

This array has a size of 5 elements, where the starting index is equal to 1, that means if we want to access the 3$ price inside of it we need to do

prices[1] -- This is equal to 3$

If we wanted to get the next we would just add 1 to the index, and so on. You need to have in mind that index starting from 1 is actually pretty rare and just a few languages have this feature, most of them use 0 as their starting index, its all the same but instead of using 1 to get the first number, you use 0

stray sphinx
#

hmmm

#

okay

#

will take my time to understand that

umbral gyro
#

Have you used Excel before?

stray sphinx
#

before pandemic

umbral gyro
#

Okay, so, in Excel, you have cells, like A1, A2, A3, etc

stray sphinx
#

yes.

valid garnet
#

example

#

u wanna make a pet system

#

this is how you would do it

stray sphinx
#

okay

valid garnet
#

simply

#
local Pets = {
Dog,
Cat,
Sheep,
Cow
}

print(Pets[1])
#

this is an index

#

it holds the names of

#

pets, whatever

#

and you can use it

#

for many

#

useful things

#

like create pet systems

#

, etc

stray sphinx
#

ohhh okay

#

very good example

umbral gyro
#

In excel, if you wanted to get the value thats in the cell A1, you would just go and do in a different cell =A1, right? Well, that 1 after the A is the index, the position of that cell, since there are a lot of cells you need to identify them somehow and we do this by indexing them, like A1, A2, A3, A4 ... A99999999,

Here in lua its the same, the index is just the position where some value is stored in, lets do this:

In Excel we can do this table:

A1: Jhon
A2: Peter
A3: Hannah

And get for example, Jhon by using A1, because it is stored in the first position, 1

In an array its the exact same, lets do it in Lua

local names = {"Jhon", "Peter", "Hannah"}

As you can see, the position remains the same, Jhon is first place, Peter is second and Hannah Third
Again, if we wanted to get the name for Jhon we would do the same as in Excel

print(names[1]) -- Prints Jhon

The index is just the position, the address of something you have stored there, by using it you are asking the computer "Hey, can you give me whats on the first cell of the array Names?" And the computer will answer you with "Yes! In the cell number 1 of Names there's this Jhon string!"

stray sphinx
#

true

#

and thanks

umbral gyro
#

👍

stray sphinx
#

much easier to understand

valid garnet
#

👍

stray sphinx
#

does index mean storage?

prime lanceBOT
#

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

stray sphinx
#

kind of

thorn jungle