Attempt to index upvalue 'legendaryPower' (a number value)

So I’ve been switching my code around to see if I could fix this as I was never able to make this work. I’m trying to display the images in a certain position based on their value. But I get “attempt to index upvalue ‘legendaryPower’ (a number value)” error 

 local legendaryPower = 10 local uniquePower = 7.5 local rarePower = 5.0 local commonPower = 2.5 ----------------------------------------------------------------------------------- --IMAGES OF MONSTERS ----------------------------------------------------------------------------------- local fireStarter = display.newImageRect( "fireType/rockStarter.png", 400, 500) fireStarter.x = centerX - 200 fireStarter.y = centerY - 350 monsters:insert( fireStarter ) fireStarter.value= uniquePower local birdFly = display.newImageRect( "flyingType/flying.png",300, 300 ) birdFly.x = centerX + 200 birdFly.y = centerY - 350 monsters:insert(birdFly) birdFly.value = commonPower local dragonQueen = display.newImageRect( "dragonType/dragon1.png", 500, 500 ) dragonQueen.x = centerX dragonQueen.y = centerY - 250 monsters:insert(dragonQueen) dragonQueen.name = "The Dragon Queen" dragonQueen.value = legendaryPower function dragonQueenListener( self , event) print( "Viewing Stats" ) end dragonQueen:addEventListener( "tap", dragonQueenListener ) -------------------------------------------------------------------------------- -- Monster Locations -------------------------------------------------------------------------------- local function monsterLocations() if legendaryPower \> uniquePower then legendaryPower.x = centerX legendaryPower.y = centerY - 250 elseif uniquePower \> commonPower then uniquePower.x = centerX + 200 uniquePower.y = centerY - 350 elseif commonPower \< legendaryPower then commonPower.x = centerX - 250 commonPower.y = centerY - 350 end end monsterLocations()

Hi,

in your function monsterLocations, you can’t set legendaryPower.x or legendaryPower.y. legendaryPower is not an “object”.

You should rather set dragonQueen.x.

This is the same with uniquePower and commonPower. You must use the images linked to these variables.

Is there a way to set values on certain monsters so depending on which monster they have it sorts itself out without having to manually putting those images in that position?

Hi,

in your function monsterLocations, you can’t set legendaryPower.x or legendaryPower.y. legendaryPower is not an “object”.

You should rather set dragonQueen.x.

This is the same with uniquePower and commonPower. You must use the images linked to these variables.

Is there a way to set values on certain monsters so depending on which monster they have it sorts itself out without having to manually putting those images in that position?