How to access an Item properties

zoultrexzoultrex
edited December 2010 in Photon Server
How do I access an Item properties just after it is subscribed by the WorldEntered class?

In the HandleEventItemSubscribed there is a function call item.GetProperties() that I guess it populates the item properties, but I dont know how to access them because the item does not have a properties variable.

Maybe im missing the point of this GetProperties function.

Comments

  • Ok here are more details about what I want to do.
    I want to add an object that the server will create to the scene and I need to know its rotation at the time it is created. I am trying to the the rotation parameter from the eventData on the HandleEventItemSubscribed function but I just realised that maybe it does not exist as I am getting an exeption of value not set to an instance.
    Maybe its because I am using an old version of photom...

    Also, the Item on the server also has this rotation value on its properties but I have no idea how to get those properties in the HandleEventItemSubscribed function call, I tried the same way to get it from the eventData but it looks like it does not have any properties key in the eventdata.

    Also, any tips how do I list all the variables in the dictionary eventData, im having a little trouble with that since all the values are different types

    My version of photon is 2.0.5.1



    UPDATE:
    foreach(DictionaryEntry k in eventData)
       {
          game.DebugLog("eData ("+k.Key+","+k.Value+" )");
       }
    
    As I suspected I looped through the eventData with the above loop and it did not contain the properties of the item or the item rotation value.
    So I guess I have to find out if its possible to change the subscribe Item eventData before its send and add those values because i really cant find where the event data is populated before sent, is that even possible?
  • It looks like the server version 2.2 doesnt have that problem, im not quite sure
    Tried to update the server DLL to the newest version but the newest DLL doesnt have the MethodReturnValue anymore.

    Also got another error a bit more serious:
    Error	2	'Photon.MmoDemo.Server.PhotonApplication' does not implement inherited abstract member 'Photon.SocketServer.Application.CreatePeer(Photon.SocketServer.PhotonPeer, Photon.SocketServer.InitRequest)'	D:\dev\AG\INova\Source\Photon\src\Photon.MmoDemo.Server\PhotonApplication.cs	29	18	Photon.MmoDemo.Server
    
    So if I just copy over the new DLL how do I fix those errors? or not. Let me know if there is another way to upgrade to the newest version =)
  • Version 2.0.5.1 required the rotation to be added manually.
    The properties hashtable doesn't contain the value, it's a c# property of MmoItem.
    If you casted the subscribed Item to MmoItem you would be able to access it, unfortunately this is not thread safe!
    GetProperties is intended to overcome the threading problem: If the properties are unknown ask the Item to push the properties. But since the rotation is not part of the properties hashtable that doesn't help here either.
    So for version 2.0.5.1 you would have to enqueue the get rotation task to the item fiber and then send the rotation later... or trigger a movement update event.

    All this is much nicer with version 2.2 since the rotation is already integrated.
    The easiest way to upgrade would probably be to reapply your 2.0.5.1 changes to the 2.2 demo.
    The good thing is that you don't have to add the rotation again.
  • Somewhere along the way when migrating to the newest version of the server I broke the rotation that comes from the server when the Idem is subscribed to the clients.
    The event data comes with the rotation values 0,0,0 and in the game the Item that is subscribed has 3 null values for the rotation x y z.

    I cant find where in the server the event is sent, I have the impression that the code is already compiled into the server dll right?

    Any tips on where should I check for code changes that broke the recent update you guys did on the rotation? Im guessing there is nothing wrong on the server side.

    Btw, I migrated from 2.0.5 to 2.2 by getting the new 2.2 project and adding my new files and the ones existing I just added my code, I dont remember overwriting any file but im not 100% sure now .
  • The subscribe event is sent in MmoClientInterestArea.OnItemSubscribed.
    If the rotation is null that probably means that your client is not sending the rotation parameter (parameter of MyItem.MoveAbsolute) or that the rotation update on the server is missing (MmoActor.ItemOperationMove, MmoItem constructor).
  • It looks like that is fine, i found something more strange yet that I wish I remembered how I achieved that :(

    When comparing the data from a clean download of the new version and my project, in the Game.cs function AddItem:
    In the clean new project I received data from both the client itself and others connected to the server
    In my project I only receive data from the client iself, I noticed a difference in the Item IDs sending the data and Im my project somehow I dont receive the data from other clients when they subscribe, really strange...


    -UPDATE-
    No, in fact I really do receive, its just the rotation thats really not there
  • is this maybe from the 2D win forms client?
  • What do you mean? the wingrid project?
  • yes
  • No not really im using the MmoDemo like the island that comes in but modified to my unity project.

    I also found out that in the MmoItem construct the rotation value from the parameter seems to always be null when I connect a new client
  • i was asking about the wingrid because it doesn't submit the rotation.
    The same seems to happen with your client.
    In case your client doesn't move after EnterWorld you may want to submit the rotation there, too.
    Check MmoDemo.Client.MyItem.EnterWorld -> this.SetPositions has null params right now.
    The null rotation is also set at Game.SetStateWorldEntered, so that needs to be fixed, too.
    The other two methods are MyItem.Spawn and MyItem.MoveAbsolute/MoveRelative.
    MoveAbsolute is called from Player.Move.. make sure this method sets a rotation parameter.
  • Reviving an old tread...

    This rotation is really not an issue anymore in the new 2.2 version, but I think it its only not an issue for when players get connect, Im not being able to create an instance of NPC item that sends the rotation when its created on the server.
    On the game side, when someone connects, the event data from ItemSubscribed contains the rotation correctly, but for an item of type NPC it does not.

    It could be quite a few things but I want to ask you guys if this makes sense that I do not get the rotation when the NPC item is subscribed.
    Among a few things on the top of my head right now it could be that when the NPC item is created the rotation is missing in the properties
    or that one of the events that is triggered when the item is created on the server does not contain the rotation (like spawn event) , if so would it be possible to add the rotation to one of these events so when the server sends that the item is created the rotation goes in too, maybe something like override the Item onSpawn method?

    Thanks in advance
  • The rotation is not stored in the properties, it's an extra Item property "Rotation", just like "Position" is.
    The events should contain the rotation if the item rotation is not null.
    You have to make sure that you set the NPC rotation when creating it.
Sign In or Register to comment.