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 10 years ago

Example:

01Array={"Hi","Bye","Hello","Thankyou"}
02Array2={"Super","Fast","Slow","Thinker"}
03StringValue="One of the Array Values"
04 
05for s=1,4 do
06wait(1)
07RandomArray=math.random(1,2)
08if RandomArray==2 then RandomArray=Array2
09else if RandomArray==1 then RandomArray=Array
10StringValue=tostring(RandomArray[s]..s,' ')
11s=s+1
12print(StringValue)
13end 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 — 10y

1 answer

Log in to vote
1
Answered by 10 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:

01Array={"Hi","Bye","Hello","Thankyou"}
02Array2={"Super","Fast","Slow","Thinker"}
03StringValue="One of the Array Values"
04 
05for s=1,4 do
06    wait(1)
07    RandomArray=math.random(1,2)
08    if RandomArray==2 then
09        RandomArray=Array2
10    else if RandomArray==1 then
11        RandomArray=Array
12        StringValue=RandomArray[s] --If s was 1 then this would print: "Hi"
13        print(StringValue)
14    end
15end
Ad

Answer this question