Datastream Lost

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.

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

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

local item = Inventory.Items[datatable.Uid]
if (item) then
	item.Properties = datatable.Properties
	if (item.OnUpdate) then item:OnUpdate() end
	local template = Inventory.Templates[datatable.TemplateName]
	if (!template) then
		--TODO: Send template error to server
	item = template:New()
	item.Uid = datatable.Uid
	item.Properties = datatable.Properties
	Inventory.Items[datatable.Uid] = item
	if (item.OnGive) then item:OnGive() end

datastream.Hook(“Inventory.Item”, Inventory.Net.OnItem)

This is what I get on the console (everything server-side):

> Inventory.DEBUG.TestCreate()...
Item a sent.
Player: Tamschi

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:)
Inventory.DEBUG = {}
function Inventory.DEBUG.TestCreate()
local item = Inventory.Templates.Item:New()
item.Properties = {}
item.Properties.Test = “PropertyTest”
Inventory.Items[item.Uid] = item

–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


function Item:Sync()
if (!self.Flag_SendToClient) then return false end
Inventory.Net.SendItem(self.Player, self)
return true

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.


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

ERROR! Module 'zlib_b64' not found!

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


Ok, this doesn’t seem to work properly. I’m off writing a more reliable stream.