ShiVa3D
Problem with sending event to users [SOLVED]
How to get the best of multi player experienceProblem with sending event to users
by DarkSoul » 03 Oct 2011, 01:29
Hi,
I'm working on a multiplayer game and I have a problem with sending data... I want to sent to players the current user list, but I can't send events to the other users. This is part of my code (this code is in 'onUserEnterSession':
I also tried "scene.sendEventToAllUsers" but nothing.
This event: user.sendEvent (newUser, "Network", "onResetPlayerList") contains this code:
When I call this event from the server, the event don't executed on the users. The variable "ImServer" indicates if the current user is the server or not, this varieable is true just if the user has created the server, in the other users the variable is false.
Does anyone know what happens?
Thanks
I'm working on a multiplayer game and I have a problem with sending data... I want to sent to players the current user list, but I can't send events to the other users. This is part of my code (this code is in 'onUserEnterSession':
- Code: Select all
if (this.ImServer ( ) == true) then
table.add ( this.Players ( ), nUserID )
local TotalUsers = table.getSize ( this.Players ( ) )
for i = 1, TotalUsers
do
local newUser = application.getUser ( table.getAt ( this.Players ( ), i - 1 ) )
user.sendEvent (newUser, "Network", "onResetPlayerList")
end
end
I also tried "scene.sendEventToAllUsers" but nothing.
This event: user.sendEvent (newUser, "Network", "onResetPlayerList") contains this code:
- Code: Select all
--------------------------------------------------------------------------------
function Network.onResetPlayerList ( )
--------------------------------------------------------------------------------
log.warning ( "Ok" )
if (this.ImServer ( ) == false) then
table.empty ( this.Players ( ) )
log.warning ( "Delete table" )
end
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
When I call this event from the server, the event don't executed on the users. The variable "ImServer" indicates if the current user is the server or not, this varieable is true just if the user has created the server, in the other users the variable is false.
Does anyone know what happens?
Thanks
Re: Problem with sending event to users
by Xdust » 03 Oct 2011, 04:37
I use this routine to hit ever user that is online.
This will send the event to every user, and is pretty much bug free. Though it may not be the absolutely most efficient.
- Code: Select all
local userCount = application.getUserCount ( )
--log.message ( "Count = " .. userCount )
for i = 1, userCount
do
local hUser = application.getUserAt ( i - 1 )
user.sendEvent ( hUser, "MainAI", "onServer_DoStuff", "Parameter1" )
end
This will send the event to every user, and is pretty much bug free. Though it may not be the absolutely most efficient.
Re: Problem with sending event to users
by DarkSoul » 03 Oct 2011, 10:50
Hello,
Thanks for the reply but the problem is the same, I think the logic is the same than my code, anyway I have tried your code but nothing... The event just runs on the server, but not on the other users, I don't understand why, I have tried if this is problem of the ports, but it is not, I have checked the game in two different computers, from the server I can see how the another user is connecting, but I can't send events. I also check the firewall and it's not the problem.
Thanks for the reply but the problem is the same, I think the logic is the same than my code, anyway I have tried your code but nothing... The event just runs on the server, but not on the other users, I don't understand why, I have tried if this is problem of the ports, but it is not, I have checked the game in two different computers, from the server I can see how the another user is connecting, but I can't send events. I also check the firewall and it's not the problem.
Re: Problem with sending event to users [SOLVED]
by DarkSoul » 03 Oct 2011, 11:31
Ok, I see what is the problem. I used the code into the "onUserEnterSession", I did not know that this affected, the problem is solved if I put this code into "onUserEnterScene". Now works very well, I can send event to all user and these can receive the data.
Thanks!
Thanks!
Re: Problem with sending event to users
by psychicsoftware » 08 Oct 2011, 21:10
It seems to be related to timing, DarkSoul. The user entering the session must not be completely set up as an object in Shiva at the time that onUserEnterSession happens. I had the same problem but fixed it by posting the event to them with a slight delay.
-

psychicsoftware - Gold Boarder

- Posts: 284
- Location: Galway, Ireland
Re: Problem with sending event to users
by DarkSoul » 09 Oct 2011, 09:05
Yes, I know, moreover, the logic of my code is: first you make the session and enter in it, and second, you load the scene and enter in it.
I don't know why I have not noticed it in my own code lol, it was my fault.
I don't know why I have not noticed it in my own code lol, it was my fault.
Re: Problem with sending event to users
by Xdust » 09 Oct 2011, 09:42
DarkSoul wrote:Yes, I know, moreover, the logic of my code is: first you make the session and enter in it, and second, you load the scene and enter in it.
I don't know why I have not noticed it in my own code lol, it was my fault.
Meh, Shiva Networking is quirky as hell.
Just get the damn thing to work, is my motto. There doesn't seem to be any established way to do anything.
7 posts
• Page 1 of 1