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

Table isn't acting like a table, why not?

This is my script:

Result1 = { }
table.insert(Result1, "hi")
table.insert(Result1, "hi")
table.sort(Result1)
local Result =table.concat(Result1)
print(Result)

If I do table.insert(Result1, "hi") it doesn't "press" enter like a table would. (I tried adding examples the forum doesn't like entering.) For example it outputs Why doesn't it do this. If I wanted to do this how would I? Because if I quote it the quote can only stay on one line. It doesn't go on to other lines is what I mean. Can anyone help me? Thanks!

Sincerely, moo1210

1 answer

✓ Accepted answer

That's because table.concat doesn't have any default delimiter -- that is -- character(s) between each concatenation operand (string entries in the array). For example:

local array = {"hello", "world"}

print( table.concat(array) ) -->

helloworld

As you can see, it just combines "hello" and "world" together without separating them. If you want to separate each entry in the concatenation, you may use the second (optional) argument of table.concat, which does just that. For example:

local array = {"hello", "world"}

print( table.concat(array, "\n") ) -->

hello

world

"\n" is an escape sequence that creates a new line in a string (it simulates the "enter key press," as you were describing).

2 comments

0

Was just gonna write this lol!! Congrats on master by the way

0

<3

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