Any JAVA experts around?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Antonio Torrecillas
Posts: 90
Joined: Sun Nov 02, 2008 4:43 pm
Location: Barcelona

Re: Any JAVA experts around?

Post by Antonio Torrecillas »

looking a bit I've seen that pgn4web.js
has some events you can handle for your purpose.

Code: Select all

// empty event APIs to be redefined

function customFunctionOnPgnTextLoad() {}
this event fires each time the GameText updates.
So, you can redefine this function and check if the length of the inner text of the Div GameText is shorter than previously.

This trick is usefull only for the displayed game, updating the table at the end of each viewed game, or in changing channel.

hope this help.
regards.
Antonio Torrecillas
Posts: 90
Joined: Sun Nov 02, 2008 4:43 pm
Location: Barcelona

Re: Any JAVA experts around?

Post by Antonio Torrecillas »

Something like:

Code: Select all

<script>
var previous = 0;
function customFunctionOnPgnTextLoad&#40;) &#123;
   var current = document.getElementById&#40;'GameText').innnerHTML.length;
   if&#40;current < previous&#41;&#123;
      location.reload&#40;);
   &#125;
   previous = current;
&#125;
</script>
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any JAVA experts around?

Post by hgm »

In the ChessLive! viewer I do something like this:

Code: Select all

function clock_tick&#40;) // called every second
&#123;
  update_clocks&#40;); // always make active clock decrement

  if&#40;current_move < downloaded_moves&#41; &#123;
    play_one_move&#40;++current_move&#41;; // auto-play next move
    delay = 0;
    return;
  &#125;

  // all moves have been played; try to fetch new ones

  if&#40;delay-- > 0&#41; return;

  game_text = get_url&#40;URL_OF_GAME&#41;;
  delay = 10; // wait 10 sec before doing next probe

  move_list = game_text.split&#40;';'); // assumes moves are separated by semi-colons.
  downloaded_moves = move_list.length;

  if&#40;downloaded_moves < current_move&#41; &#123; // fetched gameis shorter than what we had!
    // new game must have started. Do whatever you need to do in that case
    ...
    current_move = 0; // start auto-playing new game from start
  &#125;
&#125;
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Any JAVA experts around?

Post by Rebel »

Antonio Torrecillas wrote:Something like:

Code: Select all

<script>
var previous = 0;
function customFunctionOnPgnTextLoad&#40;) &#123;
   var current = document.getElementById&#40;'GameText').innnerHTML.length;
   if&#40;current < previous&#41;&#123;
      location.reload&#40;);
   &#125;
   previous = current;
&#125;
</script>
Tried it but the display of moves stalls instead. It's pretty annoying such a small thing can give so much problems. The easy way out is:

Code: Select all

<META HTTP-EQUIV="refresh" CONTENT="60">
but that's far from perfect either.

Thanks for help anyway.
casaschi
Posts: 164
Joined: Wed Dec 23, 2009 1:57 pm

Re: Any JAVA experts around?

Post by casaschi »

Rebel wrote:I am testing a live broadcast of 4 games (channel 1-4) and at the same time maintain a live ranking as you can see from the link I gave. So if a new game is started I want to automatically refresh the page that shows the new ranking.
Then you should better load the new ranking table and update only that portion of the page.
What you are doing at the moment looks like re-building your entire house every spring only because your wife wants new flowers in the garden ;-)

The easiest way of doing that is to load the ranking table in a separate html file in an iframe of the main page, then reload the iframe only. Some people here will tell you that using iframes is not a good idea and of course you should use ajax calls to load the ranking data dynamically and update the html element instead; much neater solution but requires more learning efforts for a javascript newbie.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Any JAVA experts around?

Post by Rebel »

Aha, <iframe>, works!

Thanks.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Any JAVA experts around?

Post by Rebel »

casaschi wrote: What you are doing at the moment looks like re-building your entire house every spring only because your wife wants new flowers in the garden ;-)
Well, with women, in the end it comes down to that anyway (no escape) so I am thinking a few plies ahead :wink:
Antonio Torrecillas
Posts: 90
Joined: Sun Nov 02, 2008 4:43 pm
Location: Barcelona

Re: Any JAVA experts around?

Post by Antonio Torrecillas »

please try innerHTML instead of innnerHTML

This is my mistake.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Any JAVA experts around?

Post by Rebel »

Antonio Torrecillas wrote:please try innerHTML instead of innnerHTML

This is my mistake.
Works now.