Code issues from a table

Hello! could someone let me know what am i doing wrong? please :frowning:
remove din’t worked

   local list = {
        val1 = " value 1",
        val2 = " value 2",
        val3 = " value 3"
        
    }

    list.remove(list,val1)

    print(list.val1 .. list.val2 .. list.val3)

Use table.remove not ur table. In roblox, table is a built in function
and val1 is inside of list so its list.val1

table.remove(list,1)
1 Like

The online ide tells me that it has an error :frowning:

roblox lua and normal lua is different because table is built in FOR roblox

1 Like

Oh I understand! I will use lua from the engine better
and by the way how could I use insert in my table?

Like the same.

table.insert(list,val4,--[[value,example i wanna make val 4 to value to 4]]4)
1 Like

roblox tells me that it has an error

Oh Sorry! if you wanna remove val1 then u gotta write 1 instead. If you wanna remove val2, write 2 instead. Its like index number

How i could use instead in my code? :frowning:

what do you mean by that? can u specify

I just want to have 3 values ​​in my list, remove the value 1 and then print the list and see that it removes the value 1 in the output

This worked for me! :smiley:

local list = {}

table.insert(list,3,"soy el tercero")

table.insert(list,2,"soy el segundo")

table.insert(list,1,"soy el primero")

table.remove(list,2)

print(list)
1 Like

There more to table! Watch this tutorial

1 Like

Thanks you a lot man! i will check it now :smiley:

I find tables very useful. Be sure to research!

If you don’t care about the order of things, you can use a dictionary instead and point directly to what you need since you’re using strings:

local list = {[" value1"] = true, [" value2"] = true, [" value3"] = true, value = true} -->value is the same as ["value"]

Then you can do some nifty things like checking if it exists without any loops based off of its value and NOT a numbered index:

local function dictionaryUsage(value)
	if list[value] then
		print("value exists, so let's delete it!")
		list[value] = nil
	else
		print("value doesn't exist, so let's create it!")
		list[value] = true
	end
end
dictionaryUsage("blah")
print(list) --> "blah" is added to the dictionary
dictionaryUsage(" value1")
print(list) --> " value1" is removed from the dictionary

I almost exclusively use dictionaries because of their versatility/speed; especially when dealing with varying values. The only time I ever use an incremented indexed table is when the order matters, but that’s not nearly as common

1 Like

Highly suggest not watching devking due to his methods of scripting, Alvin, and the other youtubers are the most effective way to learn.

1 Like

Thank you very much to all of you guys who have really helped me a lot! and thanks for the tips. :smiley:

2 Likes