Author Topic: Trying to figure out a bit of javascript.  (Read 806 times)

Mesnik44

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Trying to figure out a bit of javascript.
« on: December 07, 2012, 12:17:02 PM »
Hi there,

I'm looking to add a line into the default live update javascript that Corey has given to us.

What I want to accomplish is;
If tournament buyins is greater than 14 AND player left in the tournament are less than 9 AND tables left = 1
a line on the HMTL will show Cash Game: Yes

This is what I have but is not working;
TDStatus.updatePage = function()
{
  var theChipCount = parseInt(TDStatus.Vars["chipcount"]);
  var thePlayersLeft = parseInt(TDStatus.Vars["playersleft"]);
  var theTablesLeft = parseInt(TDStatus.Vars["tablesleft"]);
  var theAvgStack = thePlayersLeft == 0 ? 0 : Math.floor(theChipCount / thePlayersLeft);
  var theRound = (TDStatus.Vars["isround"] == 1) ? TDStatus.Vars["roundnum"] : "On Break (" + TDStatus.Vars["breaknum"] + ")";
  var theNewClock = TDStatus.getClockValue(TDStatus.Vars["secondsleft"]) + (TDStatus.Vars["clockpaused"] == 1 ? " (PAUSED)" : "");
  var theCashGame = (TDStatus.Vars["buyins"] => 14) + (TDStatus.Vars["playersleft"] <= 9) + (TDStatus.Vars["tablesleft"] == 1) : "YES";
  
  TDStatus.setValue("clock", theNewClock);
  TDStatus.setValue("round", theRound);  
  TDStatus.setValue("blinds", TDStatus.getChipsString(TDStatus.Vars["smallblind"]) + " / " + TDStatus.getChipsString(TDStatus.Vars["bigblind"]));
  TDStatus.setValue("nextblinds", TDStatus.getChipsString(TDStatus.Vars["nextsmallblind"]) + " / " + TDStatus.getChipsString(TDStatus.Vars["nextbigblind"]));
  TDStatus.setValue("players", thePlayersLeft + " / " + TDStatus.Vars["buyins"]);
  TDStatus.setValue("pot", TDStatus.getMoneyString(TDStatus.Vars["pot"]));
  TDStatus.setValue("tablesleft", theTablesLeft);
  TDStatus.setValue("lastupdated", "" + new Date(parseInt(TDStatus.Vars["time"]) * 1000));
  TDStatus.setValue("CashGameOn", theCashGame);

  TDStatus.LastUpdateTime = new Date().getTime();

Thanks for looking, and any help appreciated.

Mesnik44
« Last Edit: December 07, 2012, 12:18:35 PM by Mesnik44 »

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 5471
    • View Profile
Re: Trying to figure out a bit of javascript.
« Reply #1 on: December 07, 2012, 02:13:00 PM »
You didn't post any additions to the HTML file, but I'll assume you know you've got to have something there, too.  Here's what I added to TournamentStatus.html, just below the line displaying the current Pot:

      <div class="label" id="label_CashGameOn">Cash game:</div>
      <div class="value" id="CashGameOn">&nbsp;</div>
      <div class="space" id="space_CashGameOn"></div>


The line you need to fix in TournamentStatus.js is:

var theCashGame = (TDStatus.Vars["buyins"] => 14) + (TDStatus.Vars["playersleft"] <= 9) + (TDStatus.Vars["tablesleft"] == 1) : "YES";

It should read:

var theCashGame = (TDStatus.Vars["buyins"] >= 14) && (TDStatus.Vars["playersleft"] <= 9) && (TDStatus.Vars["tablesleft"] == 1) ? "YES" : "NO";

Mesnik44

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: Trying to figure out a bit of javascript.
« Reply #2 on: December 07, 2012, 02:20:19 PM »
Thanks once again Corey,

How can I ever repay you? This is exactly what I wanted.

Mesnik44

<EDIT>
PS:

Corey, I hope this is ok. I added a special thanks in my Status Updater http://mobile.hitmenpoker.com
« Last Edit: December 07, 2012, 02:39:46 PM by Mesnik44 »

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 5471
    • View Profile
Re: Trying to figure out a bit of javascript.
« Reply #3 on: December 07, 2012, 03:07:04 PM »
No need, I'm happy to help.

Cool to see a running tournament (I'm sure you're just testing) on your site.  Looks like it's updating once per second, pretty solidly.

Btw, the link you've got is to tournamentdirector.com, which is not this site.  :)

Mesnik44

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: Trying to figure out a bit of javascript.
« Reply #4 on: December 07, 2012, 03:20:56 PM »
EEK!

How embarrassing.  :-[

Sorry about that...it's fixed now.

Mesnik44