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

How do I randomize the amount of strings from a table and put them in one string?

Asked by 5 years ago

I was wondering how to do this last night, and I hope you can help. I am modifying the bubble chat script to have randomized messages.

local function createChatLine(message, bubbleColor, isLocalPlayer)

    local Strings = {'woah ', 'trip ', 'like ', 'man, ', 'help ', 'damn ', 'wow ', 'i like ', 'feels ', 'good ', 'great ', 'bad ', 'awful ', 'death ', 'drug ', '', 'please ', 'cool ', 'why ', 'go ', ''}
    local this = {}

    function this:ComputeBubbleLifetime(msg, isSelf)
        if isSelf then
            return lerpLength(msg,8,15)
        else
            return lerpLength(msg,12,20)
        end
    end


    this.Origin = nil
    this.RenderBubble = nil
    this.Message =  Strings[math.random(1,#Strings)] .. Strings[math.random(1,#Strings)] .. Strings[math.random(1,#Strings)] .. Strings[math.random(1,#Strings)]
    this.BubbleDieDelay = this:ComputeBubbleLifetime(message, isLocalPlayer)
    this.BubbleColor = bubbleColor
    this.IsLocalPlayer = isLocalPlayer

    return this
end
0
Did you try Math.random? Zikelah 20 — 5y
0
I have tried SignorOmbra 17 — 5y

Answer this question