Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Printing Shared Variables?

Hi, I made a script that contains shared variables in it I put the shared variables all under one variable called "AllVar" I printed AllVar expecting it to print out "var1, 2, true" but it only prints out "var1" why is it like that?

var1,var2,var3 = "var1", 2, true 
AllVar=var1,var2,var3

print(AllVar)

2 answers

In addition to Adark's answer, it is worth noting that it is possible to turn the table back into a tuple.

var1,var2,var3= 1,2,3;
All={var1,var2,var3};

print(unpack(All)) --> 1 2 3

Unpack has a form of unpack {…} -> …, meaning that it can be used as unpack {var1, var2, var3} -> var1, var2, var3. Good for things like function arguments.

1 comment

0

Ah, unpack is what it was. I was thinking concat, but I know that didn't work with booleans.

You can't have a single variable hold multiple values. It just doesn't work that way.

You can store them in a Table, though:

var1, var2, var3 = "var1", 2, true
AllVar = {var1, var2, var3}

print(AllVar) --Table: [memory address]
print(AllVar[1]) -- "var1"
print(AllVar[2]) -- 2
print(AllVar[3]) -- true

This discussion is preserved as it was. New answers, comments, and votes are closed.