select random player sprite ? (a nil value) error

I’m getting a (a nil value) error when i try to do this :

--player info local sequenceDataPlayer1 = {     name="normal",     frames= {25,26,27},     time = 600,     loopCount = 0        } local sequenceDataPlayer2 = {     name="normal",     frames= {28,29,30},     time = 600,     loopCount = 0        } local sequenceDataPlayer3 = {     name="normal",     frames= {31,32,33},     time = 600,     loopCount = 0        } local sequenceDataPlayer4 = {     name="normal",     frames= {34,35,36},     time = 600,     loopCount = 0        } local sequenceDataPlayer5 = {     name="normal",     frames= {73,74,75},     time = 600,     loopCount = 0        } local sequenceDataPlayer6 = {     name="normal",     frames= {76,77,78},     time = 600,     loopCount = 0        } local sequenceDataPlayer7 = {     name="normal",     frames= {79,80,81},     time = 600,     loopCount = 0        }--player info player = display.newSprite( imageSheet, "sequenceDataPlayer"..math.random(1, 7) ) --Looking at a test print : print ("sequenceDataPlayer"..math.random(1, 7) )  

It prints the data oky ‘sequenceDataPlayer1’

What Im i doing wrong here ?

You could try:

[lua]

local playerName = “sequenceDataPlayer”…math.random(1,7)

player = display.newSprite( imageSheet, playerName)

[/lua]

getting Attempt to index global ‘player’ (a nil value)

You need to pass a table representing your sequence data to newSprite.  You’re passing a string.   Put those seven sequence data tables in another table and index it with your random number.

Here’s an example with just three…

local seqData = { { name="seq1", frames= {76,77,78}, time = 600, loopCount = 0 }, { name="seq2", frames= {76,77,78}, time = 600, loopCount = 0 }, { name="seq3", frames= {76,77,78}, time = 600, loopCount = 0 } } local sequence = seqData[math.random(1,3)]

thanks davemikesell work like a charm :smiley:

You could try:

[lua]

local playerName = “sequenceDataPlayer”…math.random(1,7)

player = display.newSprite( imageSheet, playerName)

[/lua]

getting Attempt to index global ‘player’ (a nil value)

You need to pass a table representing your sequence data to newSprite.  You’re passing a string.   Put those seven sequence data tables in another table and index it with your random number.

Here’s an example with just three…

local seqData = { { name="seq1", frames= {76,77,78}, time = 600, loopCount = 0 }, { name="seq2", frames= {76,77,78}, time = 600, loopCount = 0 }, { name="seq3", frames= {76,77,78}, time = 600, loopCount = 0 } } local sequence = seqData[math.random(1,3)]

thanks davemikesell work like a charm :smiley: