sequenceData in newSprite() fails

Hi everybody,

Im creating a turn based war game.

For animate the troop, I created a sprite with the moves of each troop:

sheetSettings =

{

width = 24,

height = 31,

numFrames = 128

}

sheet = graphics.newImageSheet(“images/Germany.png”,sheetSettings)

animationData =

{

{ name=“TroopR”, start=1, count=4, time=500, loopCount = 1},

{ name=“TroopL”, start=5, count=4, time=500, loopCount = 1},

{ name=“TroopD”, start=9, count=4, time=500, loopCount = 1},

{ name=“TroopU”, start=13, count=4, time=500, loopCount = 1},

{ name=“BazookaR”, start=17, count=4, time=500, loopCount = 1},

{ name=“BazookaL”, start=21, count=4, time=500, loopCount = 1},

{ name=“BazookaD”, start=24, count=4, time=500, loopCount = 1},

{ name=“BazookaU”, start=27, count=4, time=500, loopCount = 1},

{ name=“GranadeR”, start=31, count=4, time=500, loopCount = 1},

{ name=“GranadeL”, start=35, count=4, time=500, loopCount = 1},

{ name=“GranadeD”, start=39, count=4, time=500, loopCount = 1},

{ name=“GranadeU”, start=43, count=4, time=500, loopCount = 1},

{ name=“SniperR”, start=47, count=4, time=500, loopCount = 1},

{ name=“SniperL”, start=51, count=4, time=500, loopCount = 1},

{ name=“SniperD”, start=55, count=4, time=500, loopCount = 1},

{ name=“SniperU”, start=59, count=4, time=500, loopCount = 1},

{ name=“PlaneR”, start=63, count=4, time=500, loopCount = 1},

{ name=“PlaneL”, start=67, count=4, time=500, loopCount = 1},

{ name=“PlaneD”, start=71, count=4, time=500, loopCount = 1},

{ name=“PlaneU”, start=75, count=4, time=500, loopCount = 1},

{ name=“TankLR”, start=79, count=4, time=500, loopCount = 1},

{ name=“TankLL”, start=84, count=4, time=500, loopCount = 1},

{ name=“TankLD”, start=89, count=4, time=500, loopCount = 1},

{ name=“TankLU”, start=93, count=4, time=500, loopCount = 1},

{ name=“TankHR”, start=97, count=4, time=500, loopCount = 1},

{ name=“TankHL”, start=101, count=4, time=500, loopCount = 1},

{ name=“TankHD”, start=105, count=4, time=500, loopCount = 1},

{ name=“TankHU”, start=109, count=4, time=500, loopCount = 1},

{ name=“ObusR”, start=113, count=4, time=500, loopCount = 1},

{ name=“ObusL”, start=117, count=4, time=500, loopCount = 1},

{ name=“ObusD”, start=121, count=4, time=500, loopCount = 1},

{ name=“ObusU”, start=125, count=4, time=500, loopCount = 1}

}

and cerate the sprite

sprite = display.newSprite(sheet,animationData)

When I move one troop I call MoveY(old_X_position,old_Y_position,new_X_position,new_Y_position) for move the troop

Inside the function I look for the appropiate troop for choose the correct sprite y launch the animation

– Soldier is the name of the troop, TankL, TankH,…

sprite:setSequence(tostring(soldier…“R”))

The problems is that always use the first script for all the troop and all the moves

Why?

I dont know why dont funtion the “names” of the animationData

Thanks in advance for your help

Regards!

Hi @toy_dolls_fans,

This seems to be a case where it’s not finding the sequence name that you specify, so it’s defaulting to the first. Are you sure that it’s getting the correct name for “soldier”? Can you add some print() statements in to check this? Perhaps you need to tostring() just the soldier name then concatenate the “R” (or “L” or whatever) onto that.

Basically, this seems more like a minor Lua syntax or scoping issue and it’s probably easily fixable.

Take care,

Brent

Hi,

I found a solution

In the function:

sprite:setSequence() seems that is imposible usa a “varibale” only accept text like

sprite:setSequence(“TankLL”)

and not support

local espe = “TankL”

local aux =  tostring(espe…“L”)

sprite:setSequence(aux)

Hi @toy_dolls_fans,

I tested this and it works fine for me, using the latest public build (#2189). It works with the "tostring() and also without that. Please re-check your code and ensure that you’re setting up the proper sequences, naming them exactly as required (case-sensitive), and then playing (sprite:play()) after you change the sequence.

Brent

Hi @toy_dolls_fans,

This seems to be a case where it’s not finding the sequence name that you specify, so it’s defaulting to the first. Are you sure that it’s getting the correct name for “soldier”? Can you add some print() statements in to check this? Perhaps you need to tostring() just the soldier name then concatenate the “R” (or “L” or whatever) onto that.

Basically, this seems more like a minor Lua syntax or scoping issue and it’s probably easily fixable.

Take care,

Brent

Hi,

I found a solution

In the function:

sprite:setSequence() seems that is imposible usa a “varibale” only accept text like

sprite:setSequence(“TankLL”)

and not support

local espe = “TankL”

local aux =  tostring(espe…“L”)

sprite:setSequence(aux)

Hi @toy_dolls_fans,

I tested this and it works fine for me, using the latest public build (#2189). It works with the "tostring() and also without that. Please re-check your code and ensure that you’re setting up the proper sequences, naming them exactly as required (case-sensitive), and then playing (sprite:play()) after you change the sequence.

Brent