Quote:
Originally Posted by Rollk
Hi guys
I encounter a very small problem in my script
look at this :
PHP Code:
function slot(slot_id)
local list1 = {100001,101100,101101,101102}
local rdx = math.random( 0 , 10 ) local slot1 = math.random(1,list1)
if slot_id == 1 then insert_item( slot1, rdx ) end end
I want to select an item randomly in "list1"
and have a random amount of "0 to 10"
I am sure that for you it's simple but me who starts in lua ... it is complex:mad:
|
Code:
function slot(slot_id)
local list1 = {100001,101100,101101,101102}
local rdx = math.random( 0 , 10 )
local slot1 = list1[math.random(1,table.getn(list1))]
if slot_id == 1 then
insert_item( slot1, rdx )
end
end
- You pick an item of an array via
array_name[index]
- via
table.getn(array_name) you get the itemcount(usually the max index, but in your case the count of items) of your array (if I remember correctly).
- via
math.random(1,table.getn(array_name)) you choose randomly a number between 1 and the itemcount of your array.