Variable changes its data type?

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
I pass a variable to a function. The variable is a number, but the function receives a table, which breaks later actions. What's going on here?

Code:
 TU - Event Registration: ERROR  OnBuildingConstructed cityID = 295
 TU - Event Registration: ERROR  SaveCity cityID = table: 4F74D8D8

PHP:
Events.SavegameData = Events.SavegameData or {}
Events.SavegameData.New = Events.SavegameData.New or function(self)
  local saveData = Modding.OpenSaveData()
  local o = {}
  setmetatable(o, self)
  self.__index = self
  
  o.modName = "DefaultModName"

  o.SetModName = function (self, modName)
    self.modName = modName
  end

  o.SaveCity = function (cityID, key, value)
    log:Error("SaveCity cityID = %s", cityID)
    return saveData.SetValue(string.format("%s_city%s_%s", self.modName, cityID, key), value)
  end
  
  ...
  
end

local store = Events.SavegameData:New()
store:SetModName("CiVUP")

function OnBuildingConstructed(player, city, buildingID)
	local cityID = City_GetID(city)
	MapModData.buildingsAlive[cityID][buildingID] = true
	log:Error("OnBuildingConstructed cityID = %s", cityID)
	store:SaveCity(cityID, "buildingsAlive_"..buildingID, true)
end
 
Well, what exactly does store: do? I have never seen that before. SaveUtils uses save: and not store: right?
 
Store is just an object of the SavegameData class. I use the database storage added in the spring, not SaveUtils, because it has less overhead. What I'm trying to do now is fix the problem with a global variable to set the mod name (like SaveUtils did)... it doesn't work if there's 1 copy of the tools and 2+ mods using it. There needs to be a separate object instantiated for each mod using the tools.

I think I made a mistake in setting up this class, but I'm not sure what exactly I did wrong. :think:
 
Back
Top Bottom