Jump to content

Bad argument #2 on 'random' (interval is empty)


drk

Recommended Posts

Posted

Line 107 ( the line of the error ):

      local random = math.random(1, #musics) 

#musics is:

     local musics = { 
        [ 'David Guetta - Where Dem Girls At' ] = 'http://199.167.195.194/wdga.mp3', 
        [ 'Coldplay - Paradise' ] = 'http://199.167.195.194/pd.mp3', 
        [ 'Coldplay - Viva la Vida' ] = 'http://199.167.195.194/vlv.mp3', 
        [ 'Ana Malhoa - Danza Kuduro' ] = 'http://199.167.195.194/dk.mp3', 
        [ 'Klaas - The Way' ] = 'http://199.167.195.194/tw.mp3', 
        [ 'Basshunter - All I ever wanted' ] = 'gfx/music/bh-aiew.mp3', 
        [ 'Whiz Khalifa - Black and Yellow' ] = 'gfx/music/wk-bay.mp3', 
        [ 'Skrillex - My name is Skrillex ( Remix )' ] = 'gfx/music/sx-mnis.mp3', 
        [ 'Italobrothers - Stamp on the Ground' ] = 'gfx/music/ib-sotg.mp3', 
        [ 'Madcon - Freaky like Me' ] = 'gfx/music/mc-flm.mp3', 
        [ 'Cut the Music - Greatest Deejay' ] = 'gfx/music/ctm-gd.mp3', 
        [ 'No Name - Time`s Vortex' ] = 'gfx/music/tv.mp3', 
        [ 'Manian - Welcome to the Club' ] = 'gfx/music/wttc.mp3', 
        [ 'Bon Jovi - It`s my Life' ] = 'gfx/music/iml.mp3', 
        [ 'Example - Changed the Way you Kissed Me' ] = 'gfx/music/ctwykm.mp3', 
        [ 'Example - Kickstart ( Bar 9 Remix )' ] = 'gfx/music/e-ksb9rx.mp3', 
        [ 'Ellie Goulding - Lights ( Remix )' ] = 'http://199.167.195.194/Lights.mp3', 
        [ 'Arkasia - New World Disorder' ] = '', 
        [ 'ATB - You are not Alone ( Remix )' ] = '' 
    } 

Why I get this error?

Posted
  
local musics = { 
        [ 'David Guetta - Where Dem Girls At' ] = 'http://199.167.195.194/wdga.mp3', 
        [ 'Coldplay - Paradise' ] = 'http://199.167.195.194/pd.mp3', 
        [ 'Coldplay - Viva la Vida' ] = 'http://199.167.195.194/vlv.mp3', 
        [ 'Ana Malhoa - Danza Kuduro' ] = 'http://199.167.195.194/dk.mp3', 
        [ 'Klaas - The Way' ] = 'http://199.167.195.194/tw.mp3', 
        [ 'Basshunter - All I ever wanted' ] = 'gfx/music/bh-aiew.mp3', 
        [ 'Whiz Khalifa - Black and Yellow' ] = 'gfx/music/wk-bay.mp3', 
        [ 'Skrillex - My name is Skrillex ( Remix )' ] = 'gfx/music/sx-mnis.mp3', 
        [ 'Italobrothers - Stamp on the Ground' ] = 'gfx/music/ib-sotg.mp3', 
        [ 'Madcon - Freaky like Me' ] = 'gfx/music/mc-flm.mp3', 
        [ 'Cut the Music - Greatest Deejay' ] = 'gfx/music/ctm-gd.mp3', 
        [ 'No Name - Time`s Vortex' ] = 'gfx/music/tv.mp3', 
        [ 'Manian - Welcome to the Club' ] = 'gfx/music/wttc.mp3', 
        [ 'Bon Jovi - It`s my Life' ] = 'gfx/music/iml.mp3', 
        [ 'Example - Changed the Way you Kissed Me' ] = 'gfx/music/ctwykm.mp3', 
        [ 'Example - Kickstart ( Bar 9 Remix )' ] = 'gfx/music/e-ksb9rx.mp3', 
        [ 'Ellie Goulding - Lights ( Remix )' ] = 'http://199.167.195.194/Lights.mp3', 
        [ 'Arkasia - New World Disorder' ] = '', 
        [ 'ATB - You are not Alone ( Remix )' ] = '' 
    } 
  
local themusic = musics[math.random(0, #musics)] 
  

Posted

Because you changed the indexes of the table, the table should be formatted this way

local musics = { 
        [1] = { 'David Guetta - Where Dem Girls At', 'http://199.167.195.194/wdga.mp3'}, 
        [2] = { 'Coldplay - Paradise', 'http://199.167.195.194/pd.mp3'}, 
        [3] =  
... 
} 
  
local themusic = musics[math.random(#musics)] 
local file = themusic[2] 
local title = themusic[1]  

Posted (edited)

Hey, now I get this error on line 103: attemp to index field '?'(a nil value)

line 113:

        currentSound = playSound(theSound, true) 

theSound variable is

        local theSound = sounds[math.random(2, #randoms)] 

When the music will change I get this error and the music started plays again =s

Edit: Oh, and the #randoms table is

    local randoms = { 
        'http://199.167.195.194/wdga.mp3', 
        'http//199.167.195.194/pd.mp3' 
    } 

Edited by Guest
Posted

Double click play sound:

        addEventHandler('onClientGUIDoubleClick', root, 
      function() 
          if source == music_grid then 
            local row, col = guiGridListGetSelectedItem(source) 
            if row and col and row ~= -1 and col ~= -1 then 
              local name = guiGridListGetItemText(source, row, music_grid_column) 
              local song = guiGridListGetItemData(source, row, music_grid_column) 
              if isElement(currentSound) then 
                destroyElement(currentSound) 
              end 
              currentSound = playSound(song, true) 
              guiSetText(music_name, tostring(name)) 
            else 
              if not source then 
                setRandomMusic() 
              end 
            end 
        end 
    end 
    ) 

Tables:

    local musics = { 
        [ 'David Guetta - Where Dem Girls At' ] = 'http://199.167.195.194/wdga.mp3', 
        [ 'Coldplay - Paradise' ] = 'http://199.167.195.194/pd.mp3', 
        [ 'Coldplay - Viva la Vida' ] = 'http://199.167.195.194/vlv.mp3', 
        [ 'Ana Malhoa - Danza Kuduro' ] = 'http://199.167.195.194/dk.mp3', 
        [ 'Klaas - The Way' ] = 'http://199.167.195.194/tw.mp3', 
        [ 'Basshunter - All I ever wanted' ] = 'gfx/music/bh-aiew.mp3', 
        [ 'Whiz Khalifa - Black and Yellow' ] = 'gfx/music/wk-bay.mp3', 
        [ 'Skrillex - My name is Skrillex ( Remix )' ] = 'gfx/music/sx-mnis.mp3', 
        [ 'Italobrothers - Stamp on the Ground' ] = 'gfx/music/ib-sotg.mp3', 
        [ 'Madcon - Freaky like Me' ] = 'gfx/music/mc-flm.mp3', 
        [ 'Cut the Music - Greatest Deejay' ] = 'gfx/music/ctm-gd.mp3', 
        [ 'No Name - Time`s Vortex' ] = 'gfx/music/tv.mp3', 
        [ 'Manian - Welcome to the Club' ] = 'gfx/music/wttc.mp3', 
        [ 'Bon Jovi - It`s my Life' ] = 'gfx/music/iml.mp3', 
        [ 'Example - Changed the Way you Kissed Me' ] = 'gfx/music/ctwykm.mp3', 
        [ 'Example - Kickstart ( Bar 9 Remix )' ] = 'gfx/music/e-ksb9rx.mp3', 
        [ 'Ellie Goulding - Lights ( Remix )' ] = 'http://199.167.195.194/Lights.mp3', 
        [ 'Arkasia - New World Disorder' ] = '', 
        [ 'ATB - You are not Alone ( Remix )' ] = '' 
    } 
  
    local randoms = { 
        'http://199.167.195.194/wdga.mp3', 
        'http//199.167.195.194/pd.mp3' 
    } 

setRandomMusic function:

    function setRandomMusic () 
        local theSound = randoms[math.random(#randoms)] 
        currentSound = playSound(theSound, true) 
        setTimer(currentSound, 1000, 1) 
        guiSetText(music_name, tostring(name)) 
    end 

It's not the full code, only a part.

Posted

Works perfect..

function setRandomMusic () 
    local theSound = randoms[math.random(#randoms)] 
    currentSound = playSound(theSound, true) 
    guiSetText(music_name, tostring(name)) 
end 

I removed that timer because it was useless and wrong used.

Posted

LOL Here not works...

Edit: But I have to create a timer to when the random music end's starts another, right? And you know why I get the error 'attemp to index field '?'' ??

Posted

First, the sound will never stop because you set it to loop, second, live streams doesn't has length, so you can't really know when it's over.

And third, the script doesn't output any error.

Posted

But if live streams don't have length how TG owner has made the random music for the radio of the server clan? '-'

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...