GetUID Javadoc error?

  • getUID

    public String getUID()

    Gets the globally unique ID of the player. This ID will never change, even if the player joins another server. For Steam users, this method returns the SteamID64.

    Returns:
    the globally unique player ID as a string.

    Example: Display the UID of the player1
    //The UID is a 64 bit number, so we have to use a long
    2
    long playerUID = player.getUID();



    When I try to use this example I get an error flag that A string cannot be converted to a Long? The JAVADOC uses public String when discussing it then the example shows long. I guess I can convert it but wanted to get clarification.

  • i believe it has something to do with non steam versions of the game. not sure the data type the standalone version uses. if the game was to sell on another site their id system may be different. storing the value as a string would be more usable.

  • i believe it has something to do with non steam versions of the game. not sure the data type the standalone version uses. if the game was to sell on another site their id system may be different. storing the value as a string would be more usable.

    You can get a non Steam key to run the game. I have players on my server that only have about 7 digits in their UID recorded in the Database. But that has nothing to do with the issue.


    In the JAVA version the player.getUID() pulled the Steam ID and it was a (long) return. Now it is a (String) return The example javadoc points to String in the declaration then uses it as a (long) return. But when I use the term (or exact routine in the javadoc example) I get an error flag that the string cannot be converted to a long. That means I have to read it as a string and convert it to use it as a long for my old routines and database writes or convert all the lines to look for and write a string.


    I mean maybe I am reading too much into it but seems it changed from the JAVA days from a Long to a String in the Unity API.

  • You should use;

    Java
    String playerUID = player.getUID();


    The UID is a String there is no reason to convert it to a long, unless you are planning on doing mathematical functions on it?


    You are probabaly seeing longs in the Javadoc as Red used to store the UID as a long in the old version.


    Longs aren't needed, the UID, albeit looking like a number, is an ID an not a number.


    If you really wanted to use longs though you can cast a String to a long.

    Java
    long playerUID = Long.parseLong(player.getUID());

    However, I do not recommend casting the UID. ^^

  • This was indeed changed. Internally the new version stores the UID as a string, unlike the Java version (which stored the UID as long). While Steam and the standalone just use an integer/long value to represent the account ID (==UID), there are other platforms out there which use strings instead. If we decide to release the game on other platforms in the future, it would be problematic if the UID was stored as long...


    If you really need a long value, you could cast the UID. To make sure the UID actually represents an integer or long, you can use the method Utils.StringUtils.isInteger() (which works for both integers and longs) to check the provided string, e.g:

    Java
    string uid = player.getUID();
    if (Utils.StringUtils.isInteger(uid)) {
    long playerUID = Long.parseLong(uid);
    }


    You can also find out the game platform by calling player.getPlatform() (to find out if it's a Steam version, standalone etc) ;)

  • Well the old code pulls the long from a database file and passes them to subroutine so it is used similar to mathematics in how it is used to identify and pass numbers identifying lines in a database file. So it just becomes a bunch of lines that need to be adjusted. Switch the lookup to String now makes these pulls and subroutine passes incompatible long /string lines.


    It can be converted, I get it. It seems like the easiest method. The String just creates an incompatibility with old game java subroutine passes and reads that seemed unnecessary (albeit Red51 gave his acceptable reasons). The example is wrong in JAVADOC and should be adjusted.


    A passing line example;

    Long UID = event.getPlayer().getUID();

    (result.getLong("UID")

    long amount = value.Costing(UID); //this line will flag a Long/String error if UID is changed to String. Long amount is used in math routines.

  • No biggie. I can convert it in the old code or use it as is. I just wanted to bring attention to the wrong example being wrong.

    Oh, thanks for bringing this to my attention, it's still an old example from the Java version :saint: We'll fix that with the next update ;)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!