Community Forum

writeStream / readStream on onCreate Objects

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created30.01.2011 15:13


Heady Planet-ls (Headshot XXL) 30.01.2011 15:22
If i add readStream, writeStream, readUpdateStream and writeUpdateStream to my script, then on synchronization i get a lua error:

Lua: Error running function: packetReceived
D:/code/lsim2011/build/finalbin/dataS/scripts/network/Server.lua(666) : attempt to index field '?' (a nil value)



function onCreate(self, id)
local instance = MapBGASilo:new(g_server ~= nil, g_client ~= nil);
local index = g_currentMission:addOnCreateLoadedObject(instance);
instance:load(id);
instance:register(true); -- add update routine,
end;

MapBGASilo = {};

local MapBGASilo_mt = Class(MapBGASilo, Object);

function MapBGASilo:new(isServer, isClient)
local self = Object:new(isServer, isClient, MapBGASilo_mt);
self.className = "MapBGASilo";
return self;
end;



Stefan Geiger - GIANTS Software 01.02.2011 14:24
Is MapBGASilo inherited from the class Object? The problem is that the attribute "id" does not exist, which is assigned by the class Object. Check one of game classes which inherit from Object to see how this is done. E.g. the TipTrigger class.
http://ls-mods.de/scriptDocumentation.php?lua_file=triggers/TipTrigger

Heady Planet-ls (Headshot XXL) 01.02.2011 19:16
I have added the code on the first post.

self is a table, id is the nodeId of the scriptCallback node.

The transmission over an extra Network Event Lua works fine. I lack only the transmission on player synchronization.

I think i need a solution to run a extra Network Event on synchronization.

Stefan Geiger - GIANTS Software 04.02.2011 16:08
What do you mean with player synchronization? The data that is initially sent when a player connects?

This is what is sent/read with the readStream/writeStream functions. readUpdateStream/writeUpdateStream are used to send data that might change during the lifetime of the object. This can be achieved with sending events as well, however if possible, the updateStream functions should be preferred since they use less bandwidth but they have the problem, that they are sent at some unspecified time, whereas the events are send and received in exactly the order they were created.

Heady Planet-ls (Headshot XXL) 04.02.2011 20:20
With "player synchronization" I mean if connect a player.

I have readStream/writeStream and readUpdateStream/writeUpdateStream in my script, but they dont work.

Only If a player connects then I get the Lua Error.



Heady Planet-ls (Headshot XXL) 05.02.2011 15:24
I myself have found a solution:

if g_server ~= nil then
local players = {};
for key, value in pairs(g_currentMission.players) do
table.insert(players, value);
end;
if self.serverNumPlayers ~= table.getn(players) then
self.serverNumPlayers = table.getn(players);
g_server:broadcastEvent(MPEvent:new(self));
end;
end;

If connect / leave a player then send data to other clients.


Note: Log in to post. Create a new account here.