Jump to content
Forgot your email address? ×
  • Create New...
  • 0

quest - question - problem



  • 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

2 answers to this question

Recommended Posts

  • 0
  • 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:

  • Love 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • -15% Discount in Metin2 Dev Store (01/10/2021 => 31/12/2021) => Code => 15_PCT_OCT_TO_DEC_2021

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.