forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Wed Sep 20, 2017 11:50 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help with JS
PostPosted: Thu Aug 22, 2013 5:51 am 
Offline

Joined: Thu Dec 18, 2008 12:24 pm
Posts: 55
I've got a nice new variant done, and running. But at first i had a lot of trouble getting the orders to load (the js)


When i load the game (board.php) it throws this alert 'TypeError: Cannot read property 'type' of undefined' (which dissappears when debugging is turned off)

Now I can load things it manually by calling functions from the console ( running: loadOrdersForm(); loadOrdersModel(); loadOrdersPhase(); ) AND this is my second time having this problem (except it seemed to resolve itself last time, i think there is some issue with cached order data - probably because i was messing around with deleting cached files the first time i had the problem. I can't find good error output, or figure out what's going on)

Well, ok in conclusion, huh? (oh, it may be my poor implementation of a neutral player... which probably sucks...)


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 6:12 am 
Offline

Joined: Thu Aug 15, 2013 6:14 am
Posts: 15
If you load your page in Chrome, you can use the Developer Tools to find out where in your code this error is coming from. It will be because you're trying to access the "type" property on an object that isn't defined yet.

Can you provide a link?


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 6:17 am 
Offline

Joined: Thu Dec 18, 2008 12:24 pm
Posts: 55
I wasn't getting any error messages onpage load.

and now, it has magically gone away... ( ok, i ran OrdersHTML.formInit(context, contextKey) in the console... *shrugs*)

em. i can send you a link... let me see.

http://79.97.235.50/webDiplomacy/

You should be able to reproduce the bug on this game/variant: http://79.97.235.50/webDiplomacy/board.php?gameID=23


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 6:55 am 
Offline

Joined: Thu Aug 15, 2013 6:14 am
Posts: 15
I'm not really familiar with the webDip JS, but I can tell you where the error is:

Code:
      CGs=new Array();
      Units.values().map(function(f) {
         if( f.type == 'Fleet' && f.Territory.type=='Sea' ) // <--- this is where the error is being generated
         {
            var CG=new ConvoyGroupClass();


I found this by going in to the Chrome Debugger, and putting a JavaScript break point in board.php on line 327. For some reason there's a "catch(e) { alert(e); }" there, which is why you weren't getting a line number before before.

The problem is that the Units object contains some objects that look like this:

Code:
{id: "1108", terrID: "108", countryID: "3", type: "Army"}


They don't have a territory property, which produces the error - you can't ask for the value of f.Territory.type if f.Territory is undefined.


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 6:59 am 
Offline

Joined: Thu Aug 15, 2013 6:14 am
Posts: 15
Er, sorry - the offending objects are actually these ones:

Code:
{id: "1124", terrID: "23", countryID: "3", type: "Fleet"}


since they need to be of type "Fleet" to cause this error.


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 7:05 am 
Offline

Joined: Thu Dec 18, 2008 12:24 pm
Posts: 55
Thanks, that all makes sense to me.

That is the 'what', how do i stop it (at install) is my next question - i mean, it's running some code to check if any orders for convoys should be available in the orders form. But the objects in question are automatically generated, should i over-ride this behaviour?

Or is this a default for the first time a variant is run, to generate the convoy groups (i'm not really sure) as it seems to run fine for entire games without cropping up again. Hmm.

EDIT: OR is this a versioning conflict? (with code i have running from Vdip and webdip i'm not sure they are running the same stuff...)


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 7:12 am 
Offline

Joined: Thu Aug 15, 2013 6:14 am
Posts: 15
I'm afraid I don't know - someone who knows the internals of the webDip JS would be better suited to answer your question (I don't know if every Fleet is supposed to have a Territory property, for example).

Questions I would be asking though:

1) Did you change the JS? Have a look at those changes to make sure they're not responsible
2) When the units are created, is there some step that was missed?
3) It could be a versioning thing? Mixing and matching patches will have to be done pretty carefully.

I see a lot of SQL errors at the bottom of each page on your server, so I suspect something is not right with the database, which could in turn lead to other errors. I would probably fix that first.


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 7:17 am 
Offline

Joined: Thu Dec 18, 2008 12:24 pm
Posts: 55
Tim wrote:
I'm afraid I don't know - someone who knows the internals of the webDip JS would be better suited to answer your question (I don't know if every Fleet is supposed to have a Territory property, for example).

Questions I would be asking though:

1) Did you change the JS? Have a look at those changes to make sure they're not responsible
2) When the units are created, is there some step that was missed?
3) It could be a versioning thing? Mixing and matching patches will have to be done pretty carefully.

I see a lot of SQL errors at the bottom of each page on your server, so I suspect something is not right with the database, which could in turn lead to other errors. I would probably fix that first.



Thanks for all your help!

Not sure about the SQL errors, i believe the go away when i switch off debugging (in the config file), i assumed the variant code was fine so long as it ran entire games, and i'm not planning a public sever (just sending the files to vdip when it's pla-tested)


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 7:27 am 
Offline

Joined: Thu Aug 15, 2013 6:14 am
Posts: 15
Hmm.... well, lib/html.php has the following lines of Javascript:

Code:
977                 catch( e ) {
978                 '.(Config::$debug ? 'alert(e);':'').'
979                 }


Which means that any javascript errors will be silently dropped if debug is not on. That's probably not ideal. My personal preference would be to drop those three lines - but maybe there's some reason for having them that I'm not aware of. I'll post in the Developers todo later.


Top
 Profile  
 
 Post subject: Re: Help with JS
PostPosted: Thu Aug 22, 2013 7:57 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
I can't connect to your server.
Would you mind to post your variant-code here, so I can check it out?

Oliver


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group