• Datastream Lost
    4 replies, posted
I'm writing a small inventory system while learning LUA. Most of it seems to work fine, but the datastream I'm using to send items isn't received by the client. Server: [LUA] function Inventory.Net.SendItem(player, item) local datatable = {} datatable.Uid = item.Uid datatable.TemplateName = item.TemplateName if (item.Properties) then datatable.Properties = item.Properties end datastream.StreamToClients(player, "Inventory.Item", datatable) MsgN("Item " .. item.Uid .. " sent.") --DEBUG MsgN("Player: " .. player:GetName()) --DEBUG end [/LUA] Client: [LUA] function Inventory.Net.OnItem(handler, id, encoded, datatable) MsgN("Item " .. datatable.Uid .. " received") --DEBUG if (!datatable or !datatable.Uid or !datatable.TemplateName) then --TODO: Send error to server return end local item = Inventory.Items[datatable.Uid] if (item) then item.Properties = datatable.Properties if (item.OnUpdate) then item:OnUpdate() end else local template = Inventory.Templates[datatable.TemplateName] if (!template) then --TODO: Send template error to server return end item = template:New() item.Uid = datatable.Uid item.Properties = datatable.Properties Inventory.Items[datatable.Uid] = item if (item.OnGive) then item:OnGive() end end end datastream.Hook("Inventory.Item", Inventory.Net.OnItem) [/LUA] This is what I get on the console (everything server-side): [CODE] > Inventory.DEBUG.TestCreate()... Item a sent. Player: Tamschi [/CODE] There are no errors and PrintTable(Inventory) shows that everything is properly loaded, so the error must be in the code above...
Post the code for Inventory.DEBUG.TestCreate() as well. Also, avoid using datastreams at all costs.
(On server:) [LUA] Inventory.DEBUG = {} function Inventory.DEBUG.TestCreate() local item = Inventory.Templates.Item:New() item.Properties = {} item.Properties.Test = "PropertyTest" Inventory.Items[item.Uid] = item item:GiveToPlayer(player.GetAll()[1]) end --Different file: function Item:GiveToPlayer(player) if (self.Player) then error("Item already in inventory of a player!") end self.Player = player if (self.OnGive) then self:OnGive() end self:Sync() end --[...] function Item:Sync() if (!self.Flag_SendToClient) then return false end Inventory.Net.SendItem(self.Player, self) return true end [/LUA] The idea behind this is to have item templates that can be instanced and derived to quickly set the behaviour of items on client and server without too much network usage. I'm using the uids to account for data loss. [editline]12:17AM[/editline] I need the datastream because of the Item.Properties table.
Do you have any client error on the console right as the game starts? I'm not quite sure about this, but if I remember correctly, datastream is loaded automatically on the server, but not on the client. So unless you already did it, make sure to write require("datastream") before using any datastream function.
The only thing I get is [CODE]ERROR! Module 'zlib_b64' not found! [/CODE], but that definitely happens after I require datastream. It doesn't show on the hud either. I get no errors on the client and datastream.DownstreamActive() returns false. [editline]02:26PM[/editline] Ok, this doesn't seem to work properly. I'm off writing a more reliable stream.
Sorry, you need to Log In to post a reply to this thread.