I’ve got yet another question. I’ve got a table called saveData and I’m putting the data from that data in another table by doing this:
local newSaveTable = saveData
And well, that’s working. After that I’m confirming if all the data is transferred by using some print statements:
for i=1, #newSaveTable do print("") print("----------------------------------------------------------------------") print("") print("Name: " .. newSaveTable[i].name) print("Date: " .. newSaveTable[i].date) print("Amount: " .. newSaveTable[i].amount) print("Category: " .. newSaveTable[i].category) print("ID: " .. newSaveTable[i].id) print("") print("----------------------------------------------------------------------") print("") end
And like expected, all the data is transferred. After that I’m trying to filter out some items in the table. I’m trying to delete all the items that do not include the “friend” category. I do this by doing this:
local currentScene = composer.getSceneName("current") print("Current Scene: " .. currentScene) for i=1, #newSaveTable do if newSaveTable[i].category ~= currentScene then table.remove(newSaveTable, i) end end
So in that part of code I assign currentScene and that goes as planned, nothing wrong with that. After that I’m looping through my table again like I did with all the print statements, still no problem. But the line with the if statement gives me an error:
02:32:47.100 ERROR: Runtime error 02:32:47.100 D:\PayMeBack\Code\PayMeBack\friend.lua:645: attempt to index field '?' (a nil value) 02:32:47.100 stack traceback: 02:32:47.100 D:\PayMeBack\Code\PayMeBack\friend.lua:645: in function \<D:\PayMeBack\Code\PayMeBack\friend.lua:620\> 02:32:47.100 ?: in function 'dispatchEvent' 02:32:47.100 ?: in function 'gotoScene' 02:32:47.100 D:\PayMeBack\Code\PayMeBack\main.lua:44: in main chunk
It says that I’m trying to index a nil value but I just earlier confirmed that none of the data is nil. Could someone tell me what I’m missing here?