colyseus / colyseus-haxe

⚔ Colyseus Multiplayer SDK for Haxe

Home Page:https://docs.colyseus.io/getting-started/haxe-client/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

colyseus-haxe code to swc

Shaunmax opened this issue · comments

Hello,

We successfully compiled your haxe code to generate a swc, in order to use it in Adobe AIR AS3 projects.
Our doubt is with joinOrCreate() function. In all the examples provided in the documentations, the function is only expecting 2 arguments but for us its expecting 4, may I know why?

client.joinOrCreate("my_room",null,null,function (err:MatchMakeError, room:Room):void{
            if(err){
                trace("Err = " + err.message);
            }else{
                trace(room.sessionId);
            }
        });

when passing null values, we are able to make successful connection with local server but, got some internal error like : Error #1007: Instantiation attempted on a non-constructor. unfortunately its coming from the swc, so there is no way to debug it.

image

image
Also, we dont know how to handle this schema situation in AS3?

We would really appreciate if anyone can provide some help/advice on this.

Appreciate your support!

Hey @Shaunmax,

You need to provide the generated state class for .joinOrCreate on the Haxe side.

For that, first, you need to generate the .hx files based on the TypeScript state definitions. From the command-line, in the server root path you should run:

npx schema-codegen src/rooms/schema/MyRoomState.ts --haxe --output ./path-to-haxe-sources/
Creating ./path-to-haxe-sources/ directory
generated: MyRoomState.hx

To join, then:

client.joinOrCreate("my_room", [], MyRoomState, function(err, room) {
    if (err != null) {
        trace("JOIN ERROR: " + err);
        return;
    }

    trace(room.sessionId);
});

(See joinOrCreate docs, make sure to click on the "haxe" tab!)

Hope this helps, feel free to re-open this issue if you find any problem. Cheers!

@endel Thanks for help and yes, I have successfully generate the definitions but I am getting error on the 2nd parameter

image

its expecting a parameter of type haxe.IMap . When I checked the code its showing that haxe.IMap is an interface.

When I tried with :

var imap:IMap;
       client.joinOrCreate("my_room",imap ,MyRoomState,function (err:MatchMakeError, room:Room):void{
           if(err){
               trace("Err = " + err.message);
           }else{
               trace(room.sessionId);

               room.onMessage("data", function (message){
                   trace(message.status);
               });
           }
       });

it's working without any errors.

Also I dont think I have the privilege to reopen this issue!

Please advice.

Interesting, as you're calling this from AS3 via the compiled SWC, I believe the compiler is expecting a Haxe structure instead of a built-in AS3 structure.

I'll leave this issue open in case any other member has something to add.

Interesting, as you're calling this from AS3 via the compiled SWC, I believe the compiler is expecting a Haxe structure instead of a built-in AS3 structure.

I'll leave this issue open in case any other member has something to add.

What exactly is that haxe structure? & we need to pass a null value to it right?

The structure expected is https://api.haxe.org/haxe/ds/Map.html

Not sure null is accepted, but an empty Map would. You could try exposing the haxe.ds.Map to AS3 somehow from the SWC, and provide it as the argument.

The structure expected is https://api.haxe.org/haxe/ds/Map.html

Not sure null is accepted, but an empty Map would. You could try exposing the haxe.ds.Map to AS3 somehow from the SWC, and provide it as the argument.

So its just an object or a dictionary. I dont think I can edit swc, I will have to make changes in haxe files and then compile it to swc.

@endel Can we convert Map<String, Dynamic> to Dictionary<String, Dynamic> or something similar ?

I can't figure it out by myself, also there's not much discussions in any forum about it.

I used StringMap and that solved the issue for me -

client.joinOrCreate("my_room",new StringMap() ,MyRoomState,function (err:MatchMakeError, room:Room):void{
            if(err){
                trace("Err = " + err.message);
            }else{

                myroom = room;
                trace(myroom.sessionId);

                myroom.onStateChange.push(onRoomStateChanged);
                myroom.onError.push(onRoomError);

                myroom.onMessage("hello", function (message){
                    trace("data received - " + message);
                });

                myroom.onMessage("data", function (message){
                    trace("data received - " + message.status);
                });

                myroom.onMessage("broadcast", function (message){
                    trace("broadcast received - " + message.data);
                });

                myroom.onJoin.push(onRoomJoined);

                myroom.onLeave.push(onRoomLeft);

                myroom.state.players.onAdd = onPlayerAdded;
                myroom.state.players.onChange = onPlayerChange;
                myroom.state.players.onRemove = onPlayerRemove;

            }
        });