1 posts
Posted 18 June 2014 - 12:58 PM
Hello,
I would like to create a program that displays random sentences with a redstone signal but I do not know how to do.
1190 posts
Location
RHIT
Posted 18 June 2014 - 02:28 PM
Ask a Pro is not the forum to ask for people to make a program for you. If you'd like to ask someone for code, you can make a post in the General forum. However, I cannot guarantee that someone will answer.
That being said, here are some resources that might help you program this yourself:
math.random can be used to generate random numbers, which could help you select a random sentence
Tables can be used to store some random sentences (hint: you might want to retrieve some stored sentences using math.random)
The redstone API could be used to detect whether the computer is receiving a redstone signal
os.pullEvent would allow you to detect a change in the redstone state.
Edited on 18 June 2014 - 12:29 PM
1852 posts
Location
Sweden
Posted 18 June 2014 - 03:37 PM
Check out the links above, then you'll get a better understanding of the short little code I will show you
First of all you should declare a table containing all of your sentences
local sentences = {
"Blah blah"; "This is another blah blah sentence", "Just some random stuff here";
}
then you can use math.random to access a random string from there
local sentence = sentences[math.random( 1, #sentences )]
The rest you'll have to figure out for yourself, it's very easy
19 posts
Posted 20 June 2014 - 06:03 AM
sen = {'Sentence 1', 'ect'}
print(sen[math.random(1, #sen)])
Or, if you want it to select multiple sentences…
sen = {'Sentence 1', 'ect'}
chosen={}
times = 5
for i=1,times do
local it = sen[math.random(1,#sen)]
table.insert(chosen, it)
end
-- Read the table chosen
for _,v in pairs(chosen) do
print('#'..i..' - '..v)
end
And yes, I'm pretty sure Ask a Pro is not exactly for having pros make programs for you ;)/>