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

Can a dictionary key value (if a table) hold multiple values?

Asked by 1 year ago

can ignore this stuff if you get question:

/~~~~~~~~~~~~~~~~~ Functions = {

CreateConfiguration = (function(Configurations, Table)
    --gets the table of the first parameter
    for i, v in pairs(Configurations:GetChildren()) do

        --finds if the values classname is a value
        if string.find(v.ClassName, "Value") then
            --if it make its name a clone of its value

            print(v.Name)  
            Table[v.Name] = v:Clone()

            --if it isnt and it is either a folder or configuration class 
            print(Table)
        elseif v:IsA("Folder") or v:IsA("Configuration") then
            --then make the values name become
            Table[v.Name] = Functions.CreateConfiguration(v, Table)
            print(Table[v.Name])
        end
        print(Table)
    end~~~~~~~~~~~~~~~~~

The line 16 for some reason ends up making 2 values when I print the table it makes. I don’t know why this happened.

print log: ~~~~~~~~~~~~~~~~~ ["Ammo"] = "*** cycle table reference detected ***", ["Automatic"] = Automatic, ["Bullets"] = Bullets, ["Burst"] = "*** cycle table reference detected ***", ["ClipSize"] = ClipSize, ["Damage"] = Damage, ["FireRate"] = FireRate, ["Magazines"] = Magazines, ["Offset"] = Offset, ["Range"] = Range, ["ReloadTime"] = ReloadTime, ["ToolName"] = ToolName ~~~~~~~~~~~~~~~~~ Burst is the folder then offset and bullets are its children.

2 answers

Log in to vote
0
Answered by
xXMadonXx 190
1 year ago
Edited 1 year ago

You are running the function. Now it gets to line 16, waits there and runs the same function again on line 16. Now that you are running it again, it is printing. Because it now is finished, the function you first ran can now resume on line 17 and also Prints.

voilla, you have multiple prints because you are running multiple functions.

Edit: And no, a dictionary key can not hold multiple values

Ad
Log in to vote
0
Answered by 1 year ago

No, you can’t. But you can turn multiple values into a table so it will be one value.

local SomeTable = {
   foo = "bar", "boo" --wrong

   bar = {"foo", "boo"} --correct
}

Answer this question