Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

bad argument #-2 to 'insert' (Proxy expected, got string)
Started by AngelaMcCall Nov 15 2019 01:05 PM

6 replies to this topic

Best Answer AngelaMcCall , 15 November 2019 - 03:11 PM

SOLVED!! - Figured it out!

 

instead of thinking that the image of the display.object had been stored in the array, I now know that it's only the data on an object that gets stored. Furthermore, the way the storage of an display.object is handled, is for a table of the items data be placed into the array (basically everything except a physical .png file reference).

 

So I was unknowingly trying to force a table into a display group.

 

Instead I tweaked my code to rebuild the display.object on retrieving it's reference and data from my array using 


item = display.newImageRect( "images-items/" .. getItemImageName(arrInventory[getItemIndexNum].myName) .. ".png", itemWidth, itemHeight )

getItemImageName(arrInventory[getItemIndexNum].myName)

This basically sends the known name of the item eg "Green Glass Bottle" to a quick function that strips out any spaces, making the returned name,

"GreenGlassBottle" which completes the entire path to the file name.

 

:-)

 

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

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

Hello.

I'm building a point and click adenture game.

I've an inventory, whose items are being successfully stored in my the device persisteant memory using JSON and retrieved.

 

I have sucessfully coded and printed to the console the retreival of the first 5 items, I can scroll left and right moving through the inventory all successfully.

 

So the logic and code works....

Until....

I try to put the actual display.object of the item on the screen.

 

This is the line I am attempting to code, which is causing the error:.

groupUserInterface:insert( item ) -- add item to the User Interface Group

groupUserInterface is a child group within sceneGroup.
I understand this accepts display objects.

 

This is the code, I have wrote, to cycle through my retrived inventory array

When I comment out the troublesome line, the code works by writing content of array to the console.

			-- get items 
			while ( count <= setMaxNumberItems ) do -- test iterations through opp to max 5 times
				print ( "[" ..getItemIndexNum.. "] " .. tostring(arrInventory[getItemIndexNum].myName) ) -- testing

				-- -- physically display each item in turn
				item = arrInventory[getItemIndexNum] -- get the current object 
				groupUserInterface:insert( item ) -- add item to the User Interface Group
				-- self.view:insert(item)
				item.x = itemX 
				item.y = itemY
				itemName = arrInventory[getItemIndexNum].myName
				-- item:addEventListener( "tap", updateInventoryLabel )

				-- reset variables for next loop iteration requirements
				getItemIndexNum = getItemIndexNum + 1 -- set index of next item to get
				count = count + 1 -- count up by 1, with each loop iteration
				itemX = itemX + 50 -- move the next item 50 points horizontally from left to right, based on last items location.	

			end
			count = 1 -- reset count to 1 so next time this function called it will work.
					
		end

I have googled the error message.

Most of the forums and their discussions are going over my head as a newbie.

But essentialy, I think it boils down to this...

 

My item, being retrieved out of the array is a table of information. Such as it's the items name, x and y locations and size etc.

Therefore I think the error is because I am trying to insert a table into a display group.

Please can someone confirm if my understanding of the problem so far is correct?

HOWEVER,
I just don't know what the solution is!
This is where I need help.

 

If I know everything about my item object, where/how do I code in it's display image?

 

At the moment when I create an item for a player to pick up and put in their inventory I am doing so, in the scene's game play. Wiritng it to an array in memory.

 

This is then being called in the overlay to display the full inventory of items to the player.

I want to populate the items on the screen, so thought I could just recall the item from the array, but visually this is failing, logically it is working.

 

Thanks

Angela

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



[TOPIC: post.html]
#2

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

  Best Answer

SOLVED!! - Figured it out!

 

instead of thinking that the image of the display.object had been stored in the array, I now know that it's only the data on an object that gets stored. Furthermore, the way the storage of an display.object is handled, is for a table of the items data be placed into the array (basically everything except a physical .png file reference).

 

So I was unknowingly trying to force a table into a display group.

 

Instead I tweaked my code to rebuild the display.object on retrieving it's reference and data from my array using 


item = display.newImageRect( "images-items/" .. getItemImageName(arrInventory[getItemIndexNum].myName) .. ".png", itemWidth, itemHeight )

getItemImageName(arrInventory[getItemIndexNum].myName)

This basically sends the known name of the item eg "Green Glass Bottle" to a quick function that strips out any spaces, making the returned name,

"GreenGlassBottle" which completes the entire path to the file name.

 

:-)

 


  • sporkfin likes this

[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,393 posts
  • Enterprise

Glad you solved it. It feels great when we beat back the bugs that are frustrating us. With Corona, you can't save display objects. In particular JSON only knows about numbers, strings and booleans anyway. You can save things like the X, Y locations of where an object was, the filename to use to re-create the object, other properties like rotation, alpha transparency, number of items etc.

 

Rob


  • AngelaMcCall likes this

[TOPIC: post.html]
#4

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 923 posts
  • Corona SDK

Glad you solved it. It feels great when we beat back the bugs that are frustrating us. 

 

Can I also add that it is great to see someone post a detailed answer to their own question.   

 

There's nothing more frustrating than seeing a follow up post that just says "don't worry, I fixed it" with no explanation.  Or worse still, deleting the content of the original post and replacing it with "Fixed it, Rob can you remove this post".


  • sporkfin and AngelaMcCall like this

[TOPIC: post.html]
#5

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

@Angela - That was a great explanation of the problem and I often find taking the time to thoroughly explain your problem to the rest of the group leads to a self-realized solution.  Good explaining, good thinking, good solution, great job!


  • AngelaMcCall likes this

[TOPIC: post.html]
#6

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

Glad you solved it. It feels great when we beat back the bugs that are frustrating us. With Corona, you can't save display objects. In particular JSON only knows about numbers, strings and booleans anyway. You can save things like the X, Y locations of where an object was, the filename to use to re-create the object, other properties like rotation, alpha transparency, number of items etc.

 

Rob

Thanks
I think half the problem as a newbie, is that you don't know enough about what you don't know, to be able to form accurate questions. (if that makes sense). I had to kind of work this out the hard way. But you've also mentioned a couple of others that can/cannot be saved. Thanks.



[TOPIC: post.html]
#7

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

Thanks for the positive feedback peeps :-) xx




[topic_controls]
[/topic_controls]