[AS3] - What am I doing wrong here?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

GalaxyDoomMaster
Posts: 16
Joined: 20 Mar 2018, 01:14

[AS3] - What am I doing wrong here?

Postby GalaxyDoomMaster » 27 Jan 2019, 07:41

Hey again, I'm wondering what I may be doing wrong here?

SWF File:

Code: Select all

      private static function repEx(evt:SFSEvent) : void
      {
         var vah:Object = null;
         var extType:String = null;
         var roomId:String = null;
         var optionId:Number = NaN;
         var pos:uint = 0;
         var callCommand:uint = 0;
         var option:Object = null;
         var player:* = undefined;
         var def:Number = NaN;
         var cArDef:Array = null;
         var nhj:* = undefined;
         var traceBuild:* = undefined;
         var cancelOrder:Boolean = false;
         var auto:Boolean = false;
         var unitIdStarter:Number = NaN;
         var q:* = undefined;
         var randTot:String = null;
         var randArray:Array = null;
         var vah2:Object = null;
         var o:* = evt.params.dataObj;
         if(o.cmd == "c")
         {
            swapId(o.r);
         }
         else if(o.cmd == "j")
         {
            trace("STEP J");
            s = o.mj;
         }
         else if(o.cmd == "h2")
         {
            trace("STEP H2");
            vah = {};
            vah.userNameId = ROOT.userNameId;
            fox.sendXtMessage("exRoom2","h2",vah);
         }
         else
         {
            extType = o[0];
            roomId = o[1];
            optionId = Number(o[2]);
            pos = uint(Number(o[3]));
            callCommand = uint(Number(o[4]));
            option = optionData.LIST[optionId];
            player = ROOT.GameKon["player" + pos];
            if(callCommand == 0)
            {
               trace("BUILDING ORDER REC. BUILDING ID: " + o[5]);
               traceBuild = gameKon.buildingArray[Number(o[5])];
               cancelOrder = Boolean(Number(o[6]));
               auto = Boolean(Number(o[7]));
               trace("BUILD FROM: " + traceBuild + " for Player " + player + " cancel: " + cancelOrder + " auto: " + auto);
               gameKon.doOption(option,cancelOrder,auto,player,traceBuild,true);
            }


... (code that is being focused ^)

EXTENSION:

Code: Select all

        if (cmd == "m")
        {
                trace("M: Event received: " + cmd)
            
                var response = {_cmd:cmd };
               
            var option = params.option;
            var pos = params.pos;
            var body = params.body;
            var cmd = params.cmd;
            
            trace("SM: Event received option: " + params.option)
            trace("SM: Event received pos: " + params.pos)
            trace("SM: Event received body: " + params.body)
            trace("SM: Event received cmd: " + params.cmd)
            
            response.option = option
            response.pos = pos
            response.body = body
            response.cmd = cmd
            
            trace ("----")
            
            _server.sendResponse(response, fromRoom, null, [user])
            
            trace ("SENT RESPONSE: M")
            
        }


When M is received, the code gets the option the user is selecting, the pos stands for which user, 1, 2, 3, or 4, since there can be up to 4 per match. Body doesn't return anything at the minute, and cmd is set to 0, not sure where that comes from.

Now, I am sending this response in hoping to get these variables to make a user build something. When a user clicks something, the option, aka the building they want or unit, is sent to the option variable.

In my SWF code, I want it to build something, however, nothing seems to be happening. (Note: This isn't my code, I have taken over another project and just wish to get it in some working condition after the previous person abandoned it, as such I need a bit of guidance here with what I need to do next, or what I may be missing)
User avatar
Lapo
Site Admin
Posts: 20542
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: [AS3] - What am I doing wrong here?

Postby Lapo » 28 Jan 2019, 11:54

Hi,
I am not able to follow the code... the server Extension is supposed to handle a command called "m" but I can't see any such command being sent from the client side.
What am I missing?
Lapo
--
gotoAndPlay()
...addicted to flash games
GalaxyDoomMaster
Posts: 16
Joined: 20 Mar 2018, 01:14

Re: [AS3] - What am I doing wrong here?

Postby GalaxyDoomMaster » 29 Jan 2019, 02:27

Sorry, this is what is sent from the client side, this is sent every time a player clicks on a building.

Code: Select all

public static function sendOpt(v:Object) : void
      {
         var vars:Object = new Object();
         vars.option = v.option;
         vars.pos = v.pos;
         vars.body = v.body;
         vars.cmd = v.cmd;
         fox.sendXtMessage("exRoom2","m",vars);
      }


This sends the option (what is being built)
This sends the POS (what player it is, which is 1, 2, 3 or 4.

The server extension above captures this information and sends it back, so, I presumed that it would tell the client what to do next, but doesn't seem to do anything.

When a reply is received, it runs the repEx, which is the client-code you see above.

Image
User avatar
Lapo
Site Admin
Posts: 20542
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: [AS3] - What am I doing wrong here?

Postby Lapo » 29 Jan 2019, 10:46

GalaxyDoomMaster wrote:The server extension above captures this information and sends it back, so, I presumed that it would tell the client what to do next, but doesn't seem to do anything.

According to your previous post the "M" message is received by the extension but you said the "body" parameter was missing. Correct?
If so, is exactly "body"? What kind of object is it?
Are you sure the object actually exists when it is sent from client side?

Also, as a small side note: if from the Extension you just need to send the same object you received back to the client, there's no need to create a new object and copy each field into it (I am referring to the response variable). Instead just sends the "params" object back.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
GalaxyDoomMaster
Posts: 16
Joined: 20 Mar 2018, 01:14

Re: [AS3] - What am I doing wrong here?

Postby GalaxyDoomMaster » 30 Jan 2019, 00:18

Body is returned as nothing, I'm not actually sure what it is.. but it probably isn't that important since I haven't touched any of this stuff from the original code.

cmd sends back 0.

And how would I send the params back without a new object? I mean, because of the fact I never changed any of the code, that means the original person behind the code made it use an extension, so it definitely requires it.

I'm just wondering what I am missing in my extension to make the RepEx play properly, since the debug log doesn't run the trace. The game is so so close to getting working again, just wish I could learn a little more of what exactly is or isn't working. Maybe I need to do better tracing in the code.


Edit: Did some tracing, found repEx is not being ran when the server sends a response, what must I be doing wrong here?
User avatar
Lapo
Site Admin
Posts: 20542
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: [AS3] - What am I doing wrong here?

Postby Lapo » 30 Jan 2019, 09:00

GalaxyDoomMaster wrote:Edit: Did some tracing, found repEx is not being ran when the server sends a response, what must I be doing wrong here?

Hi, sorry for not being very helpful here but I can't seem to follow.
In the original post you described an exchange with client and server that I assumed worked (at least in terms of triggers), but now it turns out that the extension handler method in the client doesn't even trigger... It's pretty difficult to guess what is going on.

You have showed a piece of code where the [b]addEventListener[()/b] is called to link the repEx function to the onExtensionResponse event, that's fine. If the event doesn't trigger I would recommend checking that the server response is actually really sent. You can double check that no errors are logged by the server when the response is sent, and also maybe add trace() statements to verify that the expected server code is actually executed.

Good luck
Lapo

--

gotoAndPlay()

...addicted to flash games
GalaxyDoomMaster
Posts: 16
Joined: 20 Mar 2018, 01:14

Re: [AS3] - What am I doing wrong here?

Postby GalaxyDoomMaster » 31 Jan 2019, 12:43

From any of the code I've shown, would there be anything in it that showcases why the repEx isn't being ran?

I have added traces in repEx and it doesn't work.

For my extension, the extension does seem to be running in the zone that the room is in, and it does read the traces and such whenever the extension and "m" command is ran, so the extension is definitely running.

Oh well, I might as well go raise my bounty in $250 for job offers so hopefully someone figures this out for me :lol:
User avatar
Lapo
Site Admin
Posts: 20542
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: [AS3] - What am I doing wrong here?

Postby Lapo » 31 Jan 2019, 16:19

GalaxyDoomMaster wrote:From any of the code I've shown, would there be anything in it that showcases why the repEx isn't being ran?

Sorry, I can't say, I don't seem to have the whole picture.

I have added traces in repEx and it doesn't work.

Well, if it doesn't show the traces in the console or logs it means that the code is never called. You will need to move further up in your chain of calls to find the problem

For my extension, the extension does seem to be running in the zone that the room is in, and it does read the traces and such whenever the extension and "m" command is ran, so the extension is definitely running.

When the server starts up it runs the Extension's init method. Make sure you trace a message in that method to make sure it's running, then check the server logs and see that no errors are present at startup.

Once this is verified, call the Extension from client side and, via trace() again, make sure that the message is logged to the console showing proper communication between the client and server example. This is the simplest check you can perform and once this is working your Extension is indeed running correctly.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
GalaxyDoomMaster
Posts: 16
Joined: 20 Mar 2018, 01:14

Re: [AS3] - What am I doing wrong here?

Postby GalaxyDoomMaster » 04 Feb 2019, 07:17

Okay, after trying many things.. I have figured out the issue:

User A (the creator of the room) is treated differently then the 3 other players (User B, C, and D)

When User A starts the game, he is kept in the 'Limbo' room, and for some reason gets removed from the lobby he was in, which he needs to remain in to be able to go into the game.

While, user B, c, and d all get into the game. Because User A wasn't in the proper room, none of the server responses were being sent.

--

Now, I have some other problems that maybe you'll understand a bit better since I'm not a goof and realizing the above earlier.

The reason the game requires us to send variables to the server and send them back, is because we send it to all clients. So that all clients receive what the game is trying to do. If player 1 builds, the server sends that information to the other clients so they know player 1 is building this thing.

--

Now, this is how I have the command "m" set up in my extension, it is ran when a user wishes to build something in the game.

Code: Select all

        if (cmd == "m")
        {
                trace("M: Event received: " + cmd)
            
                var o = {};
               
            var option = params.option;
            var pos = params.pos;
            var body = params.body;
            var cmd = params.cmd;
            
            trace("SM: Event received option: " + params.option)
            trace("SM: Event received pos: " + params.pos)
            trace("SM: Event received body: " + params.body)
            trace("SM: Event received cmd: " + params.cmd)
            
            o.optionId = option
            o.pos = pos
            o.body = body
            o.cmd = cmd
            o.traceBuild = option
            
            _server.sendResponse(o, fromRoom, null, [user])
            
            trace ("SENT RESPONSE: M")
            
        }


Now, again, the following parameters are sent to the server:

option = the ID of the building or thing being built
pos = the player
body = (I never receive anything, so I presume it is nothing for now)
cmd = (So far from testing, always sends 0)

--

Now, when the client receives a response from the server, it runs the repEx function, which, as you may have guessed will tell the game to build something with this code:

Code: Select all

gameKon.doOption(option,cancelOrder,auto,player,traceBuild,true);


The client fills in some of the blanks from someplace in the code, such as the player, the 'auto', the cancelOrder, and lastly the final 'true' at the end of it.

However, things such as: option, traceBuild, need to be filled out.

Code: Select all

traceBuild = gameKon.buildingArray[Number(o[5])];


traceBuild and option are not filled out in the doOption, so we must fill that out by sending the values from the server.

I haven't yet figured out what traceBuild is, but from what I can tell from the code:

Code: Select all

traceBuild = gameKon.buildingArray[Number(o[5])];


It is likely the same value as the option..

So, I tell it to send the 'option' and 'traceBuild' back so that it can build it, however, I get this:

Code: Select all

BUILDING ORDER REC. BUILDING ID: undefined
BUILD FROM: undefined for Player [object playerKon] cancel: false auto: false


This, meaning, the variables are undefined. But I did just send them from the server, so what gives? Did I do something wrong?

--

Lastly, I also get this error in the log file:
TypeError: Error #1010: A term is undefined and has no properties.
at mpKon$/repEx()[/Users/Krin/Flash/Colony/giraffe/mpKon.as:489]

Is this the error from the doOption function being ran with undefined variables? (doOption function creates the unit or building for example)

Or is this an error from line 489? Which is an entirely separate piece of code?

Line 486 -> 490:

Code: Select all

         else if(o.cmd == "j")
         {
            trace("STEP J");
            s = o.mj;
         }


I have tried sending 's' to it before from the server, which, if you remember in the post above. When a game room was created, it created an array with 4 values. [0,0,0,0]

The value, depending on what players will be there, will be: [0,1,2,3] (0 being player 1, 1 being player 2, so on)

So, I presumed that "s" will be what I need to define using that ^ .. so I did the same thing as I did with the repEx, but to no avail. Maybe that isn't what the error is? I tried disabling the 's' code in the extension to see and still the same error. I'm confused.

Note: Sorry for the long message, just trying to be descriptive and helpful..

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 2 guests