# Get value of a table?

You how would I get the number of one of the strings in my table, without making a for i,v loop:

``````local bubbleTable = {
["BlueBubble"] = 5000,
["PurpleBubble"] = 15000,
["PinkBubble"] = 50000,
}
``````

Lets say, I’m trying to get the purpleBubble, do do that I did:

``bubbleTable[currentBubble] -- idk how I get the value from here, CURRENT BUBBLE IS THE INDEX``
``````bubbleTable[currentBubble]
``````

should print out the value as its a dictionary.

I dont know for sure as i havent tested

edit: @pasje1312 I have a script to help you find a value

``````local bubbleTable = {
["BlueBubble"] = 5000,
["PurpleBubble"] = 15000,
["PinkBubble"] = 50000,
}

local currentBubbleString = "BlueBubble"

local currentBubbleIndex = table.find(bubbleTable, currentBubbleString) -- returns 1

local currentBubble = bubbleTable[currentBubbleIndex]

print(currentBubble)
``````
``````local bubbleTable = {
["BlueBubble"] = 5000,
["PurpleBubble"] = 15000,
["PinkBubble"] = 50000,
}

print(bubbleTable[1]) --Prints the first value
print(bubbleTable[2]) --Prints the second value
print(bubbleTable[3]) --Prints the third value
``````

Also you could change this to this:

``````local bubbleTable = {
BlueBubble = 5000,
PurpleBubble = 15000,
PinkBubble = 50000,
}

print(bubbleTable[1]) --Prints the first value
print(bubbleTable[2]) --Prints the second value
print(bubbleTable[3]) --Prints the third value
``````

so with that logic, currentBubble needs to be a number, use table.find() to return the index of the item you are looking for.

`print(bubbleTable[1])` Would print `5000`.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.