Jump to content

quest - question - problem


Recommended Posts

  • Premium

Hi guys, i have problem. I need function which show me 1 from 10 names. parex. - with number it is local numbers = number(1, 9) and system choose one number of them but i need this with words so something like local names = name(dog, dog1, dog2, dog3, dog4) and system choose one of them. Any ideas? :D  

Link to comment
Share on other sites

  • Premium

You can do it easily without any help, just build the pseudo code in your head:
 
- You have a list which contains elements, each element have an index

- You can get the size of the array by using the table.getn(ListName) function
- You can use the math.random(1, list_size) function to generate a random number between the given range
- You can get an element from the list by an index
 
So how it looks overall:
 
-- Initialize the list
DestList = { Dog, Elephant, Cat, Parrot, Monkey }
 
-- Get a random index between 1 and the length of the array
local randomValue =  math.random(1, table.getn(DestList))
 
-- Print the element at the given index:
print(DestList[randomValue])

  • Love 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.