PDA

View Full Version : [Solved] callback method is not called



sebako
01-17-2011, 04:24 AM
Hey,

i am trying to join a room, which is fine and working (at least in es admin the user is shown in the room). The Room is a persistant room called "main" in the zone "main".
But for some reason the callback method OnJoinRoomEvent isn't called and i cannot see a reason why. Some code ....





using UnityEngine;
using System.Collections;
using Electrotank.Electroserver5.Api;
using Electrotank.Electroserver5.Core;

public class gameIndex : MonoBehaviour {

// server reference
private ElectroServer _es;

// main room
Room mainR;

void Start()
{
// this es object is stored inside a unity empty game object
_es = GameObject.Find("connection").GetComponent<connection>().es;

_es.Engine.PluginMessageEvent += OnPluginMessageEvent;
_es.Engine.JoinRoomEvent += OnJoinRoomEvent;

// load lobby
loadLobby();

// request game list from server
loadGameList();
}

// this is called
void loadLobby() {
// join lobby main room - room is persistant
JoinRoomRequest jrr = new JoinRoomRequest();
jrr.ZoneName = "main";
jrr.RoomName = "main";

_es.Engine.Send(jrr);
}

// this isn't called for some reason
void OnJoinRoomEvent(JoinRoomEvent e)
{
mainR = _es.ManagerHelper.ZoneManager.ZoneById(e.ZoneId).R oomById(e.RoomId);
Debug.Log("main room joined");
}

void loadGameList()
{
PluginRequest pr = new PluginRequest();
pr.Parameters = new EsObject();
pr.Parameters.setString("action", "gameList");
pr.PluginName = "GameIndex";
pr.RoomId = mainR.Id;
pr.ZoneId = mainR.ZoneId;

_es.Engine.Send(pr);
}

// this isn't called for some reason
void OnPluginMessageEvent(PluginMessageEvent e)
{
Debug.Log("plugin message received");
Debug.Log(e.Parameters.getString("response"));
}



i have no idea why the callback methods aren't called at any single time, i have no clue what might cause this.
I have stored the es connection instance in a empty unity game object and load it inside the start method, this should work, right?

tcarr
01-17-2011, 01:39 PM
I seem to recall a problem with JoinRoomRequests that specify room name and zone name instead of roomId and zoneId. If you listen for GenericErrorResponse it will tell you why you weren't able to join that room. What happens if you switch to using a CreateRoomResponse? Do you end up in your persistent room or does it create a different room?

tcarr
01-17-2011, 02:46 PM
Here are some more things to check:

1. Enable logging to be sure what is being sent/received.

2. Make sure to set the queuing mode to external, like we have in all the unity examples, then call something like es.Engine.Dispatch() in the Update loop. This keeps the events in a thread the Unity can use.

sebako
01-17-2011, 03:43 PM
Hey Teresa,

it was indeed the dispatch type and the dispatch method call, unity simply handled everything in the usual wierd way, thats why the logmessage did not arrived. So even in case you store the es connection to an game object and call it from a script, you still have to call dispatch and set the dispatch type, otherwise unity will make crazy stuff.

Thanks alot!