Hi!
I have a table (which can be saved) in a collection. The table has 150 entries, each entry corresponds to a level, and each entry is a number (0, 1 or 2), saying whether a level is unavailable, available, or completed. So in my loader script, i have :
self.savefile= { 2,2,2,2,1,0,0,0,0,0,0,0,0,0,0... 0} -- etc., etc.
for key, value in pairs(self.savefile) do --calculates total number of levels
self.numberoflevels= self.numberoflevels+1
print(self.numberoflevels.." this is the total number of levels")
end
Now, I have a level select screen with 150 GOs, each with a label, collision object, and script. There is one GO for each level. They are the level select buttons. Each one is sent a message by the loader script.
elseif message_id == hash("getinfo") then
for key, value in pairs(self.savefile) do
local msgurl = "levelselect:/LSbutton/LSGObutton"..key.."#LSbutton" --creates URL for each level select button
msg.post(msgurl, "yourinfo", {value}) --sends each level select buttons it value
if value ==1.5 then --this line gets levels that have just become available, and makes them available
self.savefile[key] = 2
end
if key == self.numberoflevels then
local my_file_path = sys.get_save_file("bv2game", "savefile")
if sys.save(my_file_path, self.savefile) then
print("save success!")
else
print("save has failed!")
end
end
end
But it’s not working. I think because too many messages are being sent. Can anyone advise how to do this better?
Thanks!