Forum Games Multiplayer asteriods

Discussion relating to game development with Flash

Multiplayer asteriods

Postby mjdeslon » February 6th, 2010, 11:31 am

It might be too early in the morning here but I cannot figure out why the multiplayer asteriods game will not let me insert a new frame (for like a title page)

If i add a new keyframe at frame one..and put "stop();" in the action layers i get this message

Code: Select all
TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at MultiplayerAsteroids()


Any thoughts from someone with experience with the example program...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 6th, 2010, 12:31 pm

Multiplayer Asteroids uses elements attached directly to the stage with instance names as part of the user interface. Specifically base, status, mute, getgame, topbg and playertitle referred to by the class constructer and handleResize are elements created directly on the stage.

Inserting a new keyframe before everything results in those elements not existing when the constructer and subsequently handleResize is called.

If you want to insert a title screen before the game starts, you will have to ensure that the elements are not refereed to before they actually exist in the scene.

FYI, I like the idea of a title screen so I will implement it as part of the next update of the game.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 6th, 2010, 3:51 pm

Any way of posting a better commented version? I love the example but with no documentation it is hard to deciepher...once I get a better handle on what was going on in that game. I was going to create a tutorial using it.

Michael
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 6th, 2010, 6:09 pm

Yep, I will look into that at the same time.
I need to do some pretty large changes to some of the internals so might take a bit.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 6th, 2010, 8:08 pm

Benjaminsen wrote:Yep, I will look into that at the same time.
I need to do some pretty large changes to some of the internals so might take a bit.



I've started my own version...maybe we could collaborate efforts...I am sure I will need some technical help along the way...maybe I should start a blog somewhere....
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 6th, 2010, 11:56 pm

mjdeslon wrote:
Benjaminsen wrote:Yep, I will look into that at the same time.
I need to do some pretty large changes to some of the internals so might take a bit.


I've started my own version...maybe we could collaborate efforts...I am sure I will need some technical help along the way...maybe I should start a blog somewhere....


The project was made open source for the sole purpose of having several developers working on the project.
As long as the game stays open source and none profit I would love to share the development load.

You are naturally allowed to fork the project and to what you see fit with it.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 6:43 am

Ok...where did you instantiate multiplayerasteriods class...i cannot find it anywhere....
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 7:10 am

Nevermind...i'm stupid...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 7:26 am

Ok I changed the "Export Classes in Frame" to 70. Now I recieve a
Code: Select all
1120: Access of undefined property MultiplayerAsteroids
error...any suggestions?

I have the title page player login created (using a mysql database)...just have to sort out implementing the game...proving more complicated than i thought.

[
Last edited by mjdeslon on February 9th, 2010, 9:19 am, edited 1 time in total.
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 8:14 am

I think it is time for bed...i forgot to change the class name refernce to finalconquest...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 8:51 am

Eureka! I now have a version of multiplayer asteriods that now supports logins, and title screens...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 8:58 am

Ok. I will be posting the source code as soon as i add the following features.

Ability to register new players
Persistant player data (i.e. keep you exp, record deaths/kills)

Once I have those up...i'll post the source code. Give me a day or so ;)

Michael
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Oliver » February 9th, 2010, 10:32 am

Hey Michael,

Thats super awesome! Can we get a sneak peak? Where can we play it?
Also, be sure to tell us if you run into any issues; we're very helpful.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Multiplayer asteriods

Postby Benjaminsen » February 9th, 2010, 10:59 am

Just as a side note, we will release both an Auth and a Persistent data API such that you don't have to use a 3rd party database to build login systems and similar.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 5:08 pm

Benjaminsen wrote:Just as a side note, we will release both an Auth and a Persistent data API such that you don't have to use a 3rd party database to build login systems and similar.

/Chris


The way I did it was pretty simple actually...I am looking forward to what you fellas do with the API though.
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 5:09 pm

Oliver wrote:Hey Michael,

Thats super awesome! Can we get a sneak peak? Where can we play it?
Also, be sure to tell us if you run into any issues; we're very helpful.

- Oliver


As soon as i add the new player registation (today's project) i'll post up a link to the game.

Michael
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 9:20 pm

Where is the id set? I want to sync it with the playerid in the database after they login...any thoughts?


What ID are you talking about?
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 9th, 2010, 10:19 pm

I am having an issue with the kills/death/xp

I modified the "init" message handler to reflect what the database is storing:

Code: Select all
connection.addMessageHandler("init", function(m:Message, id:String, name:String, xp:Number)
         {
            me = new Ship(id,name, kills ,deaths, xp)
            me.Kills=MovieClip(root).kills;
            me.Deaths=MovieClip(root).deaths;
            me.XP=MovieClip(root).exp;
            MovieClip(root).level.text.text = XPBar.GetLevel(xp);
            userlist.AddUser(me);
            base.addChild(me)
            xpbar = new XPBar(me);
            addChild(xpbar)
            handleResize();                     
            
            doTimeSync();
         })


This seemed to work fine until another user logs in and I see that they do not display the correct kills/death/exp amounts. Where would be the correct place to change these values....
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 10th, 2010, 9:27 am

Ok. I know this is something stupid...but maybe someone here can help.

I added the following functions to the ship class

Code: Select all
public function getLoginStats(Id:String)
      {
         var variables:URLVariables = new URLVariables();
         var phprequest:URLRequest = new URLRequest("THIS IS NOT THE URL YOU ARE LOOKING FOR");
         var loader:URLLoader = new URLLoader();
         loader.addEventListener(Event.COMPLETE, onDataIn);
         variables.GameID = Id;
         phprequest.method = URLRequestMethod.POST;
         phprequest.data = variables;
         loader.dataFormat = URLLoaderDataFormat.VARIABLES;
         try
         {
            loader.load(phprequest);
         }
         catch (error:Error)
         {
            trace("Problem with getLoginStats");
         }//end try
      }
      
      public function onDataIn(e:Event):void
      {
         var variables:URLVariables = new URLVariables( e.target.data );
         this.Kills=int(variables.kills);         
         this.Deaths=int(variables.deaths);
         this.XP=int(variables.experience);
         trace("this.id:"+this.Id);
         trace("DB Kills:"+variables.kills);
      }


They are called during the "init" and "j" connection.addMessageHandler(s). The correct database value is being called, however the XP/Kills/Deaths are showing up as NAN in game...any thoughts...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 10th, 2010, 9:52 am

Have you tried tracing out e.target.data to see what's actually returned from the server?

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 10th, 2010, 2:34 pm

The database query is working fine...here is the result of onDataIn

e.target.data:experience=10&kills=5&deaths=3
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 10th, 2010, 2:38 pm

mjdeslon wrote:The database query is working fine...here is the result of onDataIn

e.target.data:experience=10&kills=5&deaths=3


When you are done loading the data, you naturally need to tell the server about it. Object properties are not automatically synched so you will have to do it manually.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby Benjaminsen » February 10th, 2010, 4:22 pm

Just had a quick look at the original game. I think there is a bug in there in general - I will have a look into it this evening my time.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Multiplayer asteriods

Postby mjdeslon » February 10th, 2010, 4:45 pm

Ok. Here is what i have done...

Server Side:

Modified GotMessage function:

Code: Select all
case "databaseupdate":
                {
                    Console.WriteLine("databaseupdate called");
                    player.Kills = Int32.Parse(m.GetString(0));
                    player.Deaths = Int32.Parse(m.GetString(1));
                    player.XP = Int32.Parse(m.GetString(2));
                    Broadcast("dbupdate", player.Id, player.Kills, player.Deaths, player.XP);
                    break;
                }


Client Side:

Modifed the ship class

Code: Select all
function Ship(id:String, title:String)
      {
         this.Id = id;
         this.Title = title;
         this.title.text = title
         this.X = x
         this.Y = y
         visible = false
      }      
      public function getLoginStats(Id:String)
      {
         var variables:URLVariables = new URLVariables();
         var phprequest:URLRequest = new URLRequest("http://mdgames.no-ip.biz/ship.php");
         var loader:URLLoader = new URLLoader();
         loader.addEventListener(Event.COMPLETE, onDataIn);
         variables.GameID = Id;
         phprequest.method = URLRequestMethod.POST;
         phprequest.data = variables;
         loader.dataFormat = URLLoaderDataFormat.VARIABLES;
         try
         {
            loader.load(phprequest);
         }
         catch (error:Error)
         {
            trace("Problem with getLoginStats");
         }//end try
      }
      
      public function onDataIn(e:Event)
      {
         var variables:URLVariables = new URLVariables( e.target.data );
         trace("e.target.data:"+e.target.data);
         var kills=variables.kills;         
         var deaths=variables.deaths;
         var XP=variables.experience;
         MovieClip(root).connection.send("databaseupdate",kills, deaths, XP);
         
      }


And in flash (previously the muliplayer asteriods class)

Code: Select all
connection.addMessageHandler("dbupdate",function(m:Message,id:String,kills:Number,deaths:Number,exp:Number )
         {
            trace("Recieved dbupdate");
            trace("ID:"+id);
            trace("Kills:"+kills);
            trace("Deaths:"+deaths);
            trace("EXP:"+exp);
            var db:Ship = ships[id] as Ship
            trace("db:"+db);
            if(db != null)
            {
               db.Kills=kills;
               db.Deaths=deaths;
               db.XP=exp;
            }
            userlist.Refresh();
         })


I am not showing the database stuff since it is working fine...

Ok. In my development server you can see the values from the database associated with the class and they are correct. But in the Userlist and XP bar they are incorrect...thoughts...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 10th, 2010, 4:47 pm

Oh on my last post the traces in the addMessageHandler display the correct values...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 10th, 2010, 5:26 pm

I believe i am really close...just ahve to adjust this function

Code: Select all
connection.addMessageHandler("dbupdate",function(m:Message,id:String,kills:Number,deaths:Number,exp:Number )
         {
            trace("Recieved dbupdate");
            trace("ID:"+id);
            trace("Kills:"+kills);
            trace("Deaths:"+deaths);
            trace("EXP:"+exp);
            var db:Ship = ships[id] as Ship
            trace("db:"+db);
            if(db != null)
            {
               db.Kills=kills;
               db.Deaths=deaths;
               db.XP=exp;
            }
            userlist.Refresh();
         })


db is returning null...everything else is as expected....thoughts...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby mjdeslon » February 11th, 2010, 4:53 am

Ok here is a screenshot of what I am seeing data is correct on the server. Individual player data is correct but other players in lobby display incorrectly.
sample.png
sample.png (144.63 KiB) Viewed 375545 times


As you can see the data is being pulled from the database properly and is sent to the server. The problem i seem to be having is from server back to client. The function i wrote works well for the indivual players but fails on other players in the lobby. I have yet to modify the death/attack functions to use the database yet...but this issue is slowing me down..


Any thoughts...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Oliver » February 11th, 2010, 11:22 am

I don't really understand what the problem is?
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Multiplayer asteriods

Postby mjdeslon » February 11th, 2010, 6:43 pm

Oliver wrote:I don't really understand what the problem is?


I am having difficulty syncing the the server with the client...the data is being lost somewhere...
User avatar
mjdeslon
 
Posts: 40
Joined: February 4th, 2010, 8:16 am
Location: Missouri

Re: Multiplayer asteriods

Postby Benjaminsen » February 11th, 2010, 6:55 pm

Sorry for not having the time to dive into your code yet. I will see if I can manage it tomorrow!

From the top of my mind I do however think the issue is that you are not broadcasting the newly joined users data to everybody when he joins.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Next

Return to Games



cron