Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Objects suddenly stopped being objects (attempt to index upvalue)?
Started by Suvoroff Oct 25 2018 01:28 AM

3 replies to this topic
corona lua newbie

Best Answer Suvoroff , 25 October 2018 - 07:16 AM

Hi Nick, thanks for your reply! I've figured out what the problem is as I was typing you a reply. All of the appropriate elements were in scope, the problem was that the image with the graphics wasn't in the folder anymore. It looks like I have accidentally deleted it as I was moving the files around in the folder while installing tile renderers! Thanks a ton for your suggestion, I would've never thought of looking for it without your hint!

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Suvoroff

[GLOBAL: userInfoPane.html]
Suvoroff
  • Observer

  • 11 posts
  • Corona SDK

Hi all!

So it's only been yesterday when I posted my first question, sure hope I won't have to bombard the forum daily. But I've got this very weird problem with absolutely zero clue about what went wrong, since this code worked perfectly yesterday, and I only altered it a bit in absolutely different part!

what%2Bthe%2Bhell.jpg

So here I am setting up the UI icons:

local map
local tower1ghost
local tower2ghost
local tower3ghost
function scene:create( event )
	local sceneGroup = self.view

	local mapData = json.decodeFile(system.pathForFile("tiles/map1.json", system.ResourceDirectory))
	map = tiled.new(mapData, "tiles")
	local background = display.newImageRect(sceneGroup, "bg_menu.png", 800, 1400)
	local tower1icon = display.newImageRect(uiLayer, objectSheet, 1, 40, 40)
	tower1icon.x = 25
	tower1icon.y = 480
	tower1ghost = display.newImageRect(uiLayer, objectSheet, 1, 40, 40)
	tower1ghost.alpha = 0.5
	tower1ghost.num = 1
	tower1ghost:addEventListener("touch", dragGhost)

And so it goes for every tower icon and 'ghost', nothing too complicated. Again, the code worked perfectly yesterday. But today, as I run it, i get:

game.lua:117: attempt to index upvalue 'tower1icon' (a nil value)

Sooo... It's okay when I slap an image on this object, but I can't set it's coordinates? I have zero clue about what's going on: everything seems to be fine with the scope and the variable has been declared. The only thing I did today is implemented PonyTiled, but even when I comment out it's code, nothing works anyway! Any ideas or at least clues?



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,610 posts
  • Corona SDK

That seems to be telling you the tower1icon doesn't exist which means there was problem during its creation.

 

Where do you create objectSheet? Is it in scope? Does it definitely have an image at index = 1? Is uiLayer a display group and in scope?


  • XeduR @Spyric likes this

[TOPIC: post.html]
#3

Suvoroff

[GLOBAL: userInfoPane.html]
Suvoroff
  • Observer

  • 11 posts
  • Corona SDK

  Best Answer

Hi Nick, thanks for your reply! I've figured out what the problem is as I was typing you a reply. All of the appropriate elements were in scope, the problem was that the image with the graphics wasn't in the folder anymore. It looks like I have accidentally deleted it as I was moving the files around in the folder while installing tile renderers! Thanks a ton for your suggestion, I would've never thought of looking for it without your hint!



[TOPIC: post.html]
#4

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,610 posts
  • Corona SDK

No problem. Dropbox has often come my rescue when a file gets deleted in between Github commits.....




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: corona, lua, newbie