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

How do I Concatenate a Specific Part of a Table using a Variable for #?

Asked by 9 years ago

Example:

Array={"Hi","Bye","Hello","Thankyou"}
Array2={"Super","Fast","Slow","Thinker"}
StringValue="One of the Array Values"

for s=1,4 do
wait(1)
RandomArray=math.random(1,2)
if RandomArray==2 then RandomArray=Array2
else if RandomArray==1 then RandomArray=Array
StringValue=tostring(RandomArray[s]..s,' ')
s=s+1
print(StringValue)
end end end

So basically what this psuedo (it doesn't work) script is suppose to do is randomly choose an array and chronologically print the values of the array values so if RandomArray=1 RandomArray=Array and if [s] = 4 then It should print the value Thankyou. The StringValue would look like this v StringValue=tostring(Array[4]..s' ') print(Array[4]..s)==print(StringValue)

Thankyou4

Novice Scripter "SamDomino"

0
thanks. SamDomino 65 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

You only need two ends and s increases by 1 by default. Also the values in the tables are already strings so there is no need for tostring() I took out the ..s,' ' because if s was 1 it would have printed "HiHi ". Finally I am pretty sure you can't put commas in the variable to concatenate that. So it would be:

Array={"Hi","Bye","Hello","Thankyou"}
Array2={"Super","Fast","Slow","Thinker"}
StringValue="One of the Array Values"

for s=1,4 do
    wait(1)
    RandomArray=math.random(1,2)
    if RandomArray==2 then
        RandomArray=Array2
    else if RandomArray==1 then
        RandomArray=Array
        StringValue=RandomArray[s] --If s was 1 then this would print: "Hi"
        print(StringValue)
    end
end


Ad

Answer this question