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

Randomly choosing a value from a table and printing it? [Answered]

Asked by 7 years ago
Edited 7 years ago

I'm trying to get my script to choose a random value from a table and then print it, but instead of text, it comes out with something like table: 1F19D310

local messages = {
    "One little piggy went to market",
    "One little doggy went to market",
    "One little child went to market",
    "One little man went to market"
}
local random = messages[math.random(#messages)]
print(random)
0
This works? User#5423 17 — 7y
0
What do you mean? This code works the way you've intended it to. It prints out a random from the array. ScriptGuider 5640 — 7y
0
I've intended it to print the text, not a random sequence. TheHospitalDev 1134 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You can't local a local. Try this:

print('Test') else print('Test2') else print('Test3') else print('Test4')

I'm not that good at random variables, sorry.

Please don't down my REP ^

0
How's this going to solve my problem? Not trying to be rude, but I don't really see how it will help. TheHospitalDev 1134 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Answered

local messages = {
    "One little piggy went to market",
    "One little doggy went to market",
    "One little child went to market",
    "One little man went to market"
}
local random = math.random(1,#messages) --Forgot to choose from the table, so it would choose #messages instead of in between them
print(messages[random]) --Prints it :3

Answer this question