Page 1 of 1

Multiple Extension

Posted: 02 Jan 2012, 21:46
by dimooze
Hi all !

I'm actually developping a game with this logic :
- login
- Then i do a PHP request to retrieive users that can play and then i create a room game for them. The room is created by the server and have its own extension to manage connection and disconnection.
- When all the users are connected to this new room i send a response to my client and i create a new AS3 class that use another extension that is the game logic.

But i think i'm wrong by doing this, because my last extension for the game logic is not associated to the room and is initialised at the start of the server. I do this because there will be different games to play randomly in order to clarify my code and not to put all my code in one extension for 6 games...

So i'm wondering if it's possible to instantiate new extension in my "general" extension
I've seen this post : http://www.smartfoxserver.com/forums/viewtopic.php?t=11724&highlight=add+extension+another+extension
Or is it possible to attach multiple extension to one room ? Is it a good way ?

I really appreciate if you can help me :)

Thanks

Posted: 03 Jan 2012, 10:57
by Bax
I suggest using 1 Zone Extension to handle rooms creation, users connections and disconnections.
And then 1 Room Extension per room, which handles the game logic.

Posted: 03 Jan 2012, 19:03
by dimooze
Thanks Bax !
I already proceed like this, but my extension for the 6 games is very very big and it's a mess to manage with it...

I've also read that it's possible to import code from another as file, in an OOP manner.

But i have to say i'm completly lost doing this in as1 is there some examples ?

Posted: 03 Jan 2012, 23:03
by Bax
I don't get why you have 1 extension for 6 games. Create 6 separate Room Extensions, each one specific to one game type, and when you create the room, attach the proper Extension to it.

Posted: 11 Jan 2012, 21:37
by dimooze
Hi Bax !

Thanks for you reply :)

I think i poorly explained my situation.
I create a room with one extension for 3 to 5 people. Then they play 3 minutes one game at the end of the first three minutes they play another game and so on for another one...
Then i can't move all my players to another room for each games every 3 minutes ?

Posted: 12 Jan 2012, 10:12
by Bax
Well you could simply divide the logic of the various games into separate classes, which are then managed by the Room extension.

Posted: 12 Jan 2012, 12:02
by A51Integrated
An easy way to do this would be to set a RoomVariable from the server side as each game starts and finishes indicating to the server which game they are playing.

Then, when an extension call is received, you can perform a switch statement on the RoomVariable and fork the handler to the correct place for that game.

Posted: 02 Feb 2012, 11:06
by dimooze
Thanks guys for your reply ! i was in holidays so, that's why i was not answering.

@bax : Ok so it was what i was thinking. But I don't know how to make it in as1, is there some examples ?

@A51 : I'm not sure to understand very well what you mean, i'm sorry. Do you mean that i have to move all people to a specific room with the game extension ?

Posted: 02 Feb 2012, 11:55
by A51Integrated
Not necessarily a new room (you could), but a new Java handler for the logic. Create a switch (if/else-if) statement in the code and direct the logic to a class that handles the appropriate logic.

Posted: 02 Feb 2012, 11:57
by dimooze
Thanks !

Ok so it's the same way than bax no ?
I code my extension with actionscript, do you know how van i do that ?

Posted: 02 Feb 2012, 12:13
by A51Integrated
Try something like this.....been a while since I wrote AS1, so I hope it works!!

Code: Select all

function init()
{
        trace("Extension init")
}

function destroy()
{
        trace("Extension destroy")
}

function handleRequest(cmd, params, user, fromRoom)
{
        var handler;
        if (cmd == "game_cmd")
        {
                switch (params.values.myGameVal)
                {
                     case 1:
                          handler = new HandlerOne(params,user,fromRoom);
                          break;
                     case 2:
                          handler = new HandlerTwo(params,user,fromRoom);
                          break;
                     //........
                }
        }
}