Forum C# player.Send problem

player.Send problem

Postby solo204 » August 1st, 2012, 4:21 pm

Hello guys,
I'm barely starting with player.io and got kind of stuck with a tut.
I have a test that goes - player.Send ("tell", "OONA") from serverside but when Actionscript 3 gets the message it's missing
the parameter and says the length is 0. No matter if I put a string, an int or whatever. :?
Thanks in advance - solo
solo204
 
Posts: 5
Joined: July 31st, 2012, 5:27 am

Re: player.Send problem

Postby Henrik » August 1st, 2012, 7:12 pm

Are you sure it's your "tell" message and not some other message?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: player.Send problem

Postby solo204 » August 1st, 2012, 8:04 pm

Yes. I created a custom type just to make sure it's the one called from actionscript.
For some reason the parameter never goes with the message. I'm confused.
Like for example - I call player.Send ("tell", "OONA") from userJoined() method - the message doesn't even
get to flash. I know because I have a trace statement that doesn't show so the method never gets called.??

Also, say after connecting - I call a _connection.send ("nameMe", "Solo");
And I have a callback function also called nameMe ($m:Message) to trace ($m.getString(0)) in as3 then
on the serverside - I have a case statement -
case "nameMe":
player.Name = message.getString(0);
Then I pass back the message with a new parameter like - player.Send ("nameMe", "Solo204");

I get it in flash like the way I sent it - "Solo" and not "Solo204"? It looks like if you have a callback in as3 the same as
the callback in C#, the message travels to the server and back without any changes.

Another thing I did was modify tell to not have any parameters when sent to serverside and
when serverside receives it - create an new message of type "nameMe" with 1 string parameter "oona"
and send that to the player. The trace statement for the nameMe callback is as3 never gets called?

Sorry for the trouble.
solo204
 
Posts: 5
Joined: July 31st, 2012, 5:27 am

Re: player.Send problem

Postby solo204 » August 1st, 2012, 8:13 pm

Let me just attach the files in question.

Thanks for your help.

C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using PlayerIO.GameLibrary;
using System.Drawing;

namespace MyGame
{
public class Player : BasePlayer
{
public string Name;
}

[RoomType("MyCode")]
public class GameCode : Game<Player>
{
// This method is called when an instance of your the game is created
public override void GameStarted()
{
// anything you write to the Console will show up in the
// output window of the development server
Console.WriteLine("Game is started: " + RoomId);

// This is how you setup a timer
AddTimer(delegate {/*code here will code every 100th millisecond (ten times a second)*/ }, 100);

// Debug Example:
// Sometimes, it can be very usefull to have a graphical representation
// of the state of your game.
// An easy way to accomplish this is to setup a timer to update the
// debug view every 250th second (4 times a second).
AddTimer(delegate
{
// This will cause the GenerateDebugImage() method to be called
// so you can draw a grapical version of the game state.
RefreshDebugView();
}, 250);
}

// This method is called when the last player leaves the room, and it's closed down.
public override void GameClosed()
{
Console.WriteLine("RoomId: " + RoomId);
}

// This method is called whenever a player joins the game
public override void UserJoined(Player player)
{
// this is how you send a player a message
//player.Send("Hello World!");

// this is how you broadcast a message to all players connected to the game
Broadcast("UserJoined", player.Id);

player.Send("tell", "secret");
}

// This method is called when a player leaves the game
public override void UserLeft(Player player)
{
Broadcast("UserLeft", player.Id);
}

// This method is called when a player sends a message into the server code
public override void GotMessage(Player player, Message message)
{
switch(message.Type)
{
// This is how you would set a players name when they send in their name in a
// "MyNameIs" message
case "MyNameIs":
//player.Name = message.GetString(0);
player.Name = "SolololololoS";
player.Send("MyNameIs",player.Name, 0xFF00FF);
//player.Send("Hello World!");
break;

case "Hello World!":
// player.Send("Hello World!");
player.Send("nameMe", "SOLO");
break;

case "tell":
Message m = Message.Create ("nameMe", "OONA");
player.Send(m);
break;

case "UserJoined":
player.Send("tell", "OONA");
break;
}
}

Point debugPoint;

// This method get's called whenever you trigger it by calling the RefreshDebugView() method.
public override System.Drawing.Image GenerateDebugImage()
{
// we'll just draw 400 by 400 pixels image with the current time, but you can
// use this to visualize just about anything.
var image = new Bitmap(400,400);
using(var g = Graphics.FromImage(image))
{
// fill the background
g.FillRectangle(Brushes.Blue, 0, 0, image.Width, image.Height);

// draw the current time
g.DrawString(DateTime.Now.ToString(), new Font("Verdana",20F),Brushes.Orange, 10,10);

// draw a dot based on the DebugPoint variable
g.FillRectangle(Brushes.Red, debugPoint.X,debugPoint.Y,5,5);
}
return image;
}

// During development, it's very usefull to be able to cause certain events
// to occur in your serverside code. If you create a public method with no
// arguments and add a [DebugAction] attribute like we've down below, a button
// will be added to the development server.
// Whenever you click the button, your code will run.
[DebugAction("Play", DebugAction.Icon.Play)]
public void PlayNow()
{
Console.WriteLine("The play button was clicked!");
}

// If you use the [DebugAction] attribute on a method with
// two int arguments, the action will be triggered via the
// debug view when you click the debug view on a running game.
[DebugAction("Set Debug Point", DebugAction.Icon.Green)]
public void SetDebugPoint(int x, int y)
{
debugPoint = new Point(x,y);
}
}
}


AS3

package
{
import flash.display.Sprite;
import flash.events.Event;
import playerio.Client;
import playerio.Connection;
import playerio.Message;
import playerio.PlayerIO;
import playerio.PlayerIOError;

/**
* ...
* @author Solo
*/
[Frame(factoryClass="Preloader")]
public class Main extends Sprite
{

public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
initPlayerIO ();
}

private function initPlayerIO():void
{
var gameID:String = 'hello-world-yvftcqcwtucwpufioin9g';
//var gameID:String = 'tut2-e5cxope10e24qwcoc1iwrq';

PlayerIO.connect (stage, gameID, 'public', 'GuestUser', '', '', hancleConnect, handleError);
}

private function hancleConnect($client:Client):void
{
$client.multiplayer.developmentServer = '127.0.0.1:8184';
$client.multiplayer.createJoinRoom ('test', 'bounce', false, { }, { }, handleJoin, handleError);
}

private function handleJoin($connection:Connection):void
{

$connection.addMessageHandler ('Hello World!', handleMessage);
//$connection.addMessageHandler ('tell', nameMe);
//$connection.addMessageHandler ('tell', tell);
$connection.addMessageHandler ('nameMe', nameMe);
$connection.addMessageHandler ('hello', hello);
//$connection.addMessageHandler ('MyNameIs', nameMe);

//$connection.send ('Hello World!');
$connection.send ('tell');
//$connection.send ('MyNameIs', "Sololoyo");
}

private function nameMe($m:Message):void
{
trace ('nameMe '+$m.length);
}

private function hello($m:Message):void
{
trace ($m.type);
}

private function tell($m:Message):void
{
trace ($m.type, $m.length);
}

private function handleMessage($m:Message):void
{
trace ('got message back from server ', $m.type);
}

private function handleError($error:PlayerIOError):void
{
trace ($error.message);
}

}

}
solo204
 
Posts: 5
Joined: July 31st, 2012, 5:27 am

Re: player.Send problem

Postby solo204 » August 2nd, 2012, 4:54 am

Hi -
Nevermind. It's got a lot to do with the roomtype property.
Funny how there's not so much doc about it. I thought using "bounce" was OK for all of them. Then I went back to
review the first tut - FridgeMagnets and saw how the roomtype made so much difference.

Thanks anyway ;)
solo204
 
Posts: 5
Joined: July 31st, 2012, 5:27 am


Return to C#