Utilities Error

Discussion in 'Server and Client Scripting' started by Teutonic Knight, Aug 1, 2013.

  1. Teutonic Knight

    Teutonic Knight Banned

    Joined:
    Jul 2, 2013
    Messages:
    75
    Likes Received:
    0
    PO Trainer Name:
    William Hlas
    Well, I was going by the small guide to scripting i found here and I encountered an error when I made the utilities.js

    script:
    Code (text):
    1.  
    2. ({
    3.     counter: 0
    4.     ,
    5.     afterLogIn: function (src)
    6.     {
    7.         sys.sendAll("Script: Hello " + sys.name(src) + ", how are you?");
    8.         sys.sendAll("You are the " + this.utilities.formatNth(++this.counter) + " person to log in this script run!");
    9.     }
    10.     ,
    11.     beforeLogOut: function(src)
    12.     {
    13.         sys.sendAll("Script: Goodbye " + sys.name(src));
    14.     }
    15.     ,
    16.     utilities: sys.exec("utilities.js")
    17. });
    18.  
    Utilities
    Code (text):
    1.  
    2. ({
    3.     formatNth: function (num)
    4.     {
    5.         return num.toString() + (["th", "st","nd","rd"][++this.counter] || "th");
    6.     }
    7. });
    8.  
    And when the third person logs in it sends out the wrong rd/th/st/nd/

    [​IMG]
     
  2. Crystal Moogle

    Crystal Moogle Ayaya~ Administrator Administrator

    Joined:
    Jul 19, 2010
    Messages:
    3,205
    Likes Received:
    531
    PO Trainer Name:
    Hanako
    You're adding one to the counter twice (once when calling the function and once actually in the function). Use num instead of ++this.counter in the Utilities file.
     
  3. ArchZombie

    ArchZombie Member

    Joined:
    Aug 1, 2012
    Messages:
    65
    Likes Received:
    0
    PO Trainer Name:
    ArchZombie0x
    Yes, that's definitely an error.

    It's been fixed now, you can check the wiki for an updated script.