Could use some help on this extension

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Could use some help on this extension

Postby Onion » 12 Feb 2011, 02:35

I am currently working on a custom extension and no matter how many examples I look at, I cannot find one that meets my answer.

I currently have 3 eventhandlers (login, zone login, and server ready), I was setting up a database read and a timer in the server read eventhandler but ran into an issue. I need to access the SFSExtension class which calls the eventhandler for exchanging information purposes. I have tried getParentExtension() but that only gives me functions that are based off of SFSExtension and won't let me grab functions inside the class. I also created a version of the class in the eventhandler class only to do exactly what I thought would happen which is have two seperate instances going.

Is there a way to grab information from the SFSExtension class (main extension class) from the eventhandler class (CWServerReadyEventHandler.class) that is part of the original instance?

code:
addEventHandler(SFSEventType.SERVER_READY, CWServerReadyEventHandler.class);

Basically I have resulted to moving everything out of the eventhandler and putting it into the SFSExtension class I created. This brings me to another problem as well. The RPGExtension sample given shows how to use serielization for transfering objects which is great but if I create a requesthandler to send the information I will once again run into the issue of exchanging information and being able to transfer what I need to the player. The example given has it all being wrote into the game through code and not through updating and grabbing information from the database.

Any help is much appreciated.
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Clarify

Postby Onion » 12 Feb 2011, 17:36

Ok since I didnt get any responses and after reading my thread I thought it might need a little clarifying.

Basically my situation is understanding and not really the code. If anyone could help me understand I would really appreciate it.

If you have just 3 classes (One is your SFSExtension (testSFS) and the other is your eventhandler or it can be a request handler (handlerSFS), and the third is the class that stores the information from the database(INFOSFS).

In your SFS Extension class which we will call testSFS I have an instance of a class that is holding information and I have the eventhandler or requesthandler... here is some quick code:

Code: Select all

class testSFS extends SFSExtension
{
    public infoSFS info = new infoSFS();

   public void init()
   {
     addEventHandler(SFSEventType.USER_LOGIN,  handlerSFS.class);
   }
}   
 


Now inside of the handler class I simply check user login and if it all works like it should I want to send to my client something from the infoSFS class instance which has probably been updated and changed since the player last logged in. I know how to send the information, what I am running into is how to access the information.

Normally when I create code I allow access to other classes by passing the instance into the constructor of the classes. This allows me to grab information and exchange it when normally I couldn't unless I wanted to make something static or global which I try to avoid at all costs.

So a few questions with this:

Is there a way for me to access the instance of infoSFS inside of the eventhandler class or a request handler class?

If there isn't what would be suggested in order to grab information from a database, change the information through a timer, and allow the user to request the same information on demand as well as update the information of what they changed? I am not asking for code as much as how to access the information since it is being done through eventhandlers and requesthandlers?

Any other examples out there for the sfsx 2x that could help me through understanding how exactly information moves around inside the extension that aren't already shown on the doc page.

Thanks for your help.
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Postby tchen » 12 Feb 2011, 18:34

Upcast the object from getParentExtension to whatever your class happens to be.

Code: Select all

testSFS ext = (testSFS)getParentExtension()
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Postby Onion » 12 Feb 2011, 19:44

You rock.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 52 guests