Problems using SendXtMessage in BOO.

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

shivafang
Posts: 15
Joined: 24 Mar 2010, 12:23

Problems using SendXtMessage in BOO.

Postby shivafang » 04 May 2010, 11:28

Using Unity and SFSPro, client scripts are using boo script, server side python.

The client is connected and the server sends initial information (A list of possible empire and career choices - and species but the only playable one is Human ATM) to the client. So I know that my client and server are talking to each other over localhost.

smartFox.SendXtMessage("Login", "createChar", key)
does not trigger an error (Where key is of type Boo.Lang.Hash - a hastable. Any other object type triggers an error about invalid object types, which isn't mentioned in the docs.)

I've tried sending it to a Zone extension ("Login") and a Room Extension ("CreateChar"). I have joined the room that the Room Extension is loaded into, and confimed that the user is joined in the admin panel (also, the trigger for the server to send the menu information is someone joining that room, so the fact that I'm receiving the menu information indicates that I've joined the room.)

Both handlerequests look something like this;

Code: Select all

def handleRequest(cmd, params, who, roomId, protocol):
   _server.trace("Login Request")
   _server.trace(cmd)
   _server.trace(params)
   _server.trace(who)
   _server.trace(roomID)
   _server.trace(protocol)


Nothing fancy, basically a confirmation that I am receiving the message. However, the server has no response, no errors or anything.

I found a thread on the forum with someone with a similar problem, and they said they fixed it by adding "SmartFox.Connection = smartFox" to their OnConnect(), however I tried that and SmartFox is not a recognized variable. Is there another module I need to import besides the SmartFoxClientAPI? (Also tried things like SmartFoxClient.Connection and SmartFoxClientAPI.SmartFox.Connection to no avail)
Last edited by shivafang on 14 May 2010, 11:53, edited 1 time in total.
shivafang
Posts: 15
Joined: 24 Mar 2010, 12:23

Postby shivafang » 08 May 2010, 12:16

Ok, clearly I overcomplicated the problem, because no one is answering.

My question is simply "How do I sent a message from the Client to an Extension" the methods I've tried out of the documentation don't work.

Everyone who uses SFSPro has figured this out, and I'd appreciate it if someone could help me figure it out, since this is basic functionality that my project simply cannot function without.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 08 May 2010, 18:53

You can check the tic-tac-toe example (#3) that comes with the API.

It has extension communication.

In C# though - with Boo you are on your own (literely - never heard of anyone actually using it for SFS) :D

/T
shivafang
Posts: 15
Joined: 24 Mar 2010, 12:23

Postby shivafang » 10 May 2010, 21:26

Hmm I think I figured out my problem. When I pulled LoginGUI into my project it gave me the SmartFox not recognized error I had before, but when I pulled SmartFox.cs in that went away. HOWEVER, it didn't go away automatically in my boo script. I'm guessing that boo doesn't automatically recognize the cs as a class (And my initial attempts to import it havn't been very good).

Which means I'll likely have to rewrite it in C#, which means I have to learn C#.

I code in BOO because BOO is like Python, and I like Python. Actually, Python support was what initially drew my to SmartFoxServer.

Anyways, now I have a major lead that I can work on to figure it out as opposed to nothing. Thanks Thomas.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 11 May 2010, 06:22

Unity has an issue with cross language compilation, where it compiles one language before the other (usually its between C# and javascript that I've seen it, but might be an issue too with Boo)

There is a small trick documented in the Unity manuals on this. I think its a matter of moving all your C# code to the Editor folder, so it gets compiled prior to your Boo code. But it also means that the C# code cannot reference anything in the Boo code.

/Thomas
shivafang
Posts: 15
Joined: 24 Mar 2010, 12:23

Postby shivafang » 14 May 2010, 11:28

For posterity - in case anyone else needs this info (renamed the thread also, so it's easier to find.);
I managed to get it working. I rewrote the SmartFox class in Boo (wasn't a complicated class), and I also went through the LoginGUI in the Tris example and converted everything I didn't already have to BOO.

I hadn't learned about the onServerDebugMessage event, which told me that the reason it wasn't working is because I was trying to send something that wasn't a Hashtable. (Boo.Lang.Hash is a type of System.Collections.Hashtable, but it wasn't working). I wound up using the String message and using;

Code: Select all

message as System.Collections.ArrayList = System.Collections.ArrayList()


To specifically create an ArrayList for the String message sending. Functionally, these take the same commands that Boo arrays do, but are accepted by the SendXTMessage.

It wasn't a complete loss, while I was working I learned about Queued mode, which is reccomended for Unity but wasn't in the walkthrough I was following. I also learned more about C#'s delegation, and devised a work around since Boo couldn't do it that way (I could only assign one function to the delegation, not multiple. Boo dosn't like function+= function but accepted function=function, this was the way I had it before but I realised that it might cause problems if two scripts wanted the same event). I wound up creating a class specifically to delegate functions and store them in a list to parse through when the event is triggered - a technique that will serve me well when I start working on the combat code for my project.

While rewriting I also did a few other things that will save me aggrivation in the future that aren't directly related to SmartFox. Actually, it was the fact that I could call the SmartFox class without importing it first that gave me a few ideas. (I'm coming off of python, so .net is new to me even though BOO has similarities) I wound up creating a class that served as a communication 'channel' between two scripts rather using getComponent() to get the scripts directly. This allowed me to completely compartmentalize my network code to use in other scenes rather than relying on it to specifically talk to my Login GUI (which I have as a separate script)

Anyways, thanks for your help, Thomas. I glanced quickly at the examples originally and it seemed like they didn't have any extension code in them, so you pointing that out was a big help. I learn best by reverse-engineering code.

There is a small trick documented in the Unity manuals on this. I think its a matter of moving all your C# code to the Editor folder, so it gets compiled prior to your Boo code. But it also means that the C# code cannot reference anything in the Boo code.


If this ever becomes necessary for me, it would feel natural. I'm coming from multiverse which used Jython server-side. You had to compile Java for high end stuff and python for low end stuff, and the Java couldn't call any Python commands.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 17 guests