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

Printing Shared Variables?

Asked by 8 years ago

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

Log in to vote
2
Answered by 8 years ago

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.

0
Ah, unpack is what it was. I was thinking concat, but I know that didn't work with booleans. adark 5487 — 8y
Ad
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

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

Answer this question