Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to get same numbers in a table?

Asked by 5 years ago

I was wondering how to get the value two or more numbers that are the same in a table

0
set different indexes in the table to the same number: tbl[a] = num; tbl[b] = num theking48989987 2147 — 5y
0
x = {5, 100}; print(x[1]) --> 5; print(x[2]) --> 100 pidgey 548 — 5y

1 answer

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago

Indexing is basically grabbing values in the table.

local Table = {1,2,3}
local Index = math.random(1,3)

print("Selected number - "..Table[Index])

In the code above we have a table with three values, 1, 2, and 3. We have a variable which has a randomized value of 1 through 3.

We print the line the array is in using the Index variable.

Example:

Table
    1 - 1
    2 - 2
    3 - 3

    The left number represents the line the specific value is in.
    The right number represents the value of the line its on.

So above is an array which has the following:

The 1st line has the value of 1. The 2nd line has the value of 2. The 3rd line has the value of 3.

We get a random line number using math.random(1,3).

We get 2.

We search for the 2nd line in the table. It's value is 2!

We print that and in the output it should read "Selected number - 2"

More info about tables/indexing can be found here

0
my solution was local Tabe = {1,2,3,5,5,5,6} local num = 0 local nvn = 0 tie = false for i = 1,#Tabe do if Tabe[i] > num then num = Tabe[i] elseif Tabe[i] == num then nvm = Tabe[i] tie = true end end for i = 1,#Tabe do if Tabe[i] == num and nvm == num then print(Tabe[i],num,nvm) tie = true else print(Tabe[i],num,nvm) tie = false end end print(tie) TheMaleWhale_png 82 — 5y
0
Yeah, I got majorly confused by his question. Mr_Unlucky 1085 — 5y
Ad

Answer this question