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....
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?
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.