I've been hitting a wall on this issue and I can't seem to resolve it. It's very strange and I haven't had it before.
In my C# code, I have the "init" function return the user's ID and their username for each user. I then send this information to the AS3 "init", and of course since we don't know how long the message will be (since it depends on the number of users), I use a for loop. Yet this loop is never executed; indeed, any time I try to mention m.length anywhere in my AS3 "init" code, the game breaks. Here's my code:
C#:
- Code: Select all
public override void UserJoined(Player player)
{
Message newInit = Message.Create("init");
if (totalPlayers == 0)
{
owner = player;
playersIn[0] = player;
totalPlayers++;
}
else
{
for (int i = 0; i < 50; i++)
{
if (playersIn[i] == null)
{
playersIn[i] = player;
totalPlayers++;
i = 50;
}
}
}
newInit.Add(player.Id, player.username, owner.Id, owner.username);
for (int j = 0; j < 50; j++)
{
if (playersIn[j] != null && playersIn[j] != player)
newInit.Add(j,playersIn[j].Id, playersIn[j].username);
}
player.Send(newInit);
}
This works fine, and always outputs a message with a finite length.
AS3:
- Code: Select all
connection.addMessageHandler("init", function(m:Message, thisID:int, thisName:String, theOwner:int, ownerUser:String)
{
trace(m.length) //breaks
testbox.text = m.length.toString() //breaks
totalPlayers++
myID = thisID
myName = thisName
ownerID = theOwner
ownerName = ownerUser
for (var a = 4; a < m.length; a+=3)//Never executes
{
userIDs[m.getInt(a)] = m.getInt(a + 1)
userNames[m.getInt(a)] = m.getString(a + 2)
}
})
I have no clue how to move forward on this. Can anyone help?