View Full Version : Retrieve EsObject keys
joseph
03-28-2011, 08:47 AM
I am running into the problem of needing to reassign a declared EsObject 'EsObj'. Can this be done in a Unity Built in Method such as: void Start(){}?
private void onPluginMessageEvent(PluginMessageEvent e)
{
if (e.PluginName != PLUGIN_NAME)
{
// we aren't interested, don't know how to process it
return;
}
EsObject esob = e.Parameters;
//....
}
Ideally, I'd like to assign the esob in the Unity Start method.
tcarr
03-28-2011, 11:24 AM
The problem is that if this esob comes from a plugin message event, how is the script getting the esob? If you explain more what you are trying to do, perhaps I'll have an idea. Is the esob coming from some other script?
joseph
03-28-2011, 06:48 PM
Yes, the esob is set in another script. Can I assign it to some member of the GameManager 'gm' object without having to pass any paramaters? For example, can I assign the esob object in the void Start() { } method?
tcarr
03-28-2011, 06:52 PM
I'm still not sure what you are talking about, but you could certainly add a variable to GameManager with a getter and a setter, and then any script that can access GameManager can look up the value of that variable. You would have to pass a parameter to GameManager when you set the value, right? Unless it's a public field and you set it directly instead of using a setter.
joseph
03-28-2011, 07:02 PM
It is similar to what I did with the GameManager gm object to keep the connection through scene changes:
GameObject gameManager = GameObject.Find("_GameManager");
GameManager gm = (gameManager)gameManager.GetComponent<GameManager>( );
es = gm.es; //I want to do this with the esObject
In my first scene I am using the Main.cs from the AvatarChat Unity example. Then in my second scene (before I join the room to chat which is the third scene) I am setting the esob using the functions setString and setInteger. However, I need something to reassign to the 'new' esObj that I will declare in the script that outputs it, reallocating it will overwrite my keys..Similar to what we do with the GameManager gm above shown above.
I think the trouble for me is the iteration scheme in the SimpleChat example:
foreach (User u in currentRoom.Users) {
GUILayout.Button(u.UserName); //This was apparently set using the LoginRequest.UserName variable.
}
I am trying to do:
foreach (User u in currentRoom.Users) {
GUILayout.Button(EsObj.getString("Player") + " " + EsObj.getString("Profession));
}
However, when I declare and instantiate the EsObj:
private EsObject EsObj;
void Start() {
EsObj = new EsObject();
}
The keys are lost, which is correct because I am overwritting the EsObject instance with a new one. How can I keep that information by assigning the EsObj with something from GameManager (if that it allowed)?
tcarr
03-28-2011, 08:02 PM
You could get the old EsObject from GameManager, and then read that, and then write the values into the new one. The easiest way to clone an EsObject is to use the addAll function. So you get the EsObject from GameManager (call it gmEsob), and create the new EsObj, then do EsObj.addAll(gmEsob). See if that works for you.
joseph
03-28-2011, 08:09 PM
Thanks, you were right the first time. All I needed to do was add more setters and getters with the appropriate naming conventions and access them through the GameManager 'gm' object. In short, its working now.
One thing that I have been noticing however, is whenever I leave the room and re-join the, I get run-time errors here:
foreach (User u in currentRoom.Users) {
GUILayout.Button(gm.userName + gm.profession + gm.level);
}
Is there a technique for leaving and rejoining a room? I included the OnJoinRoom delegate for whenever I enter, but I am not doing anything for when I exit.
tcarr
03-28-2011, 08:21 PM
When you leave a room, the currentRoom's Users list is wiped, because you aren't allowed to see the userlist for a room you aren't in. Are you sure that you are updating the currentRoom variable when you get the JoinRoomEvent? It won't update itself automatically, you have to take the roomId and zoneId from the event and look up the room variable in ZoneManager.
joseph
03-28-2011, 08:56 PM
Unfortunately, I just noticed that after building another web player, the members for the gm object become overwritten when multiple users join a room, for example:
foreach (Users u in currentRoom.users) {
GUI.Button(gm.userName + gm.profession + gm.level);
}
null is drawn for the username and the profession and the level are overwritten by the last user that joined. So i can't really work on joining and/or re-joining a room just yet :(
tcarr
03-28-2011, 09:40 PM
That looks good to me. Hmmm I bet that these lines:
foreach (User u in currentRoom.Users) {
GUILayout.Button(gm.userName + gm.profession + gm.level);
}
are being executed while you aren't in the room (because it's normally run every frame), which means that currentRoom.Users is now null. Perhaps you need to enclose that code snippet in an IF or a TRY. I'm rather confused as to why you are putting the gm.userName + gm.profession + gm.level on a button for each user in the room, instead of trying to get each user's information (at least his username).
joseph
03-28-2011, 10:23 PM
I edited my post from earilier and unfortunately noticed that after building another web player, some members that I added for the gm object become overwritten when multiple users join a room, for example:
GUILayout.BeginArea(new Rect(5,100,100,100));
foreach (Users u in currentRoom.users) {
GUI.Button(gm.userName " " + gm.profession + " " + gm.level);
}
GUI.EndArea();
gm.userName is empty (e.g. nothing is drawn) and the profession and the level are overwritten by the last user that joined. So i can't really work on handeling re-joining a room just yet :(
tcarr
03-28-2011, 11:15 PM
This seems to be a bug with your custom Unity code, not with ES5 or the way that ES5 works. I don't think I'll be able to help you with it.
joseph
03-28-2011, 11:37 PM
That is strange.
I found that it will, in fact, work correctly when including your Main.cs file in my character selection scene. This is because I concatenated each of the players' properties into the LoginRequest lr.UserName varaible (which is displayed using GUI.Button). I saw that nothing will be overwritten that way.
Thus, I am trying to implement your ConnectAndLoginManually.cs code in my first scene, then go about joining a room (e.g. making the LoginRequest), THEN set the lr.UserName varaible when I click the enter tavern button. So before the tavern scene, I set the lr.UserName varaible which will have the selected players properties. Then we are in the actual tavern, which has your SimpleChat.cs file and will display all the Users.
tcarr
03-28-2011, 11:46 PM
I'm rather confused. Is ONE human logging in becoming multiple players? Or are you referring to various avatars that the one human might choose, and that human then picks one of them?
If the situation is multiple human beings, then they each log in separately. They know their own information. After they join the room, they can get information about the other users in the room from the plugin.
joseph
03-29-2011, 12:15 AM
I could send you the game link privately if you'd like? My design is as follows:
1) In the first scene i display the username and password textfields that the user *should enter* to validate his or her account. This is not functional yet. I am currently just estasblishing a connection in this scene.
2) In the second scene we choose between 4 characters (four slots) and intend on entering the tavern -- to chat amoungst other potential connected clients
3) in the third scene i want to display my character logged in. Suggesting that it shoud be displayed for any other client connected to ES5.
It all works as it should *offline*. Playerprefs is able to make the distinction between which slot has the character type, level, proffession, guild, inventory, etc..
yes, to answer your question one human is logging and has the option to choose between 1/4 characters they had created to enter the tavern room to chat with other potentially connected clients
tcarr
03-29-2011, 12:23 AM
Ok, so the human is choosing one of the 4 possible characters. You need to remember which one has been chosen. You don't need to join a room before choosing the character, right? Just wait until after you have chosen the character, then store the info about that character into the GameManager object, and then switch scenes, joining the room in the next scene.
joseph
03-29-2011, 12:37 AM
I have done that..and logged in multiple times choosing different characters, and the information is still overwritten. The only way that the user information willl not be overwritten is by assigning the LoginRequest lr.UserName varaible prior to joining a room -- thats why i decided to concatenate the lr.UserName variable with the data in playerprefs..
foreach (Users u in currentRoom.Users) {
GUI.Button(u.UserName); // will display the information that i concatenated prior to joining the room (is current now)
GUI.Button(gm.userName + " " + gm.userProfession + " " + gm.userLevel); //same as above but gets overwritten
}
but that is the thing, I can't seem to make another login request to reassign the varaible prior to joining the room. I might have forgot to mention (in this post at least) that the chosen characters information intially goes awry only when testing a Web Player Build.
tcarr
03-29-2011, 01:08 AM
Another login request? Are you logging out and then back in again? Because that won't work well. And each user logged in to ES5 needs a unique username. If you are already logged on, just stay logged on. You need to have an avatar name that is separate from the username, is all, and display that instead of the username.
Or perhaps I've totally misunderstood what you are trying to do. I can try again tomorrow - already put in way too many hours at work today.
joseph
03-29-2011, 01:19 AM
Thanks very much, i'll try and get this solved asap.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.