Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Set large int to yml

Comments in 'Plugin Development' started by dxm_hippie, Mar 12, 2016.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I am trying to save a very large number to a yml.. number to save is -861031530247370120 and the number it saves as the key in the yml file is -1691235720 o_O why is that? and is there a way to fix this or are numers that big not allowed in yml files? it works with a text file d:
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Is your integer between the range of PHP_INT_MIN and PHP_INT_MAX?

    And also, what about casting the number to float first?
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    How can i see what the php int min is? i tried the constant..not recognized but the min is usaly just the same as the max but negative right? and max is 9223372036854775807 so min should be -9223372036854775807.. i am on windows 64 bit
  4. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I have tried float and string :p same outcome
  5. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Trying to write -1869275236685471920 ends up writing 2045615872... no matter what format i make the number. I have var_dump the int also to make sure it was right and it is.
  6. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I dont get it..that is inside of the php int limits. Is there some law with yml files? maybe ill take a stab at a db and see how that goes bc a text file wont work for what i need it for..it could but would be impractical lol
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    dxm_hippie likes this.
  9. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Is that a bug with YAML? and this means i cant use the Config::YAML? /: what type might be best for this? I decided to go with sqlite3 even tho i have no idea how to use it XD quickly learning tho..just having some issues getting all "primary keys" as array.
  10. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    If you really need to save it, and the digits are consistent all the time, how about splitting it into two different floats, and put them together when you need it? (substr())
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Im using clientId to create a tempban so no its never the same..didnt want to say bc its not "PocketMine"...but pm is inactive and genisys has a working UUID (the large int) that i am having loads of fun with XD i already got it all set with sqlite3 also, wasn't to hard to figure out. Also that wouldn't of been very practical either lol i was thinking of storing the uuid to a text file with the players name inside..then i could get the name/uuid that way and have the name in a yml saying how many days they have left of temp ban but that is all way to funky. Figuring out sql was more fun anyway :p
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually you could just cast the int to a string. Cast back to int when you use it.
  13. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I tried to do that using strval and got the same result.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It shouldn't. Just (string) when setting to config, (int) when getting from config.
  15. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I tried that also i believe..and (float)
    $this->getConfig()->set((string)$id, array(yadayada));
    when that didn't work i tried the strval
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you show code? That is unreasonable; PHP shouldn't truncate a string as if it is an int.

    Wait, are you on 32-bit or 64-bit?
  17. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    That code i sent there was just a example :p I am on 64 bit and have tried..

    PHP:
    $id $player->getClientId();
            
    $now date("Y-m-d");
            
    $file = new Config($this->getServer()->getDataPath().'TempBans.yml'Config::YAML, array());
            
    $file->set($id, [
                
    'Ban-On' => $now,
                
    'Days-Left' => $days
                
    ]);
            
    $file->save();
    output
    Code:
    2045615952:
      Ban-On: "2016-03-17"
      Days-Left: "1"
    PHP:
    $id = (string)$player->getClientId();
            
    $now date("Y-m-d");
            
    $file = new Config($this->getServer()->getDataPath().'TempBans.yml'Config::YAML, array());
            
    $file->set($id, [
                
    'Ban-On' => $now,
                
    'Days-Left' => $days
                
    ]);
            
    $file->save();
    output
    Code:
    2045615952:
      Ban-On: "2016-03-17"
      Days-Left: "1"
    PHP:
    $id strval($player->getClientId());
            
    $now date("Y-m-d");
            
    $file = new Config($this->getServer()->getDataPath().'TempBans.yml'Config::YAML, array());
            
    $file->set($id, [
                
    'Ban-On' => $now,
                
    'Days-Left' => $days
                
    ]);
            
    $file->save();
             
    var_dump($id); // string(20) "-1869275236685471920"
    output
    Code:
    2045615952:
      Ban-On: "2016-03-17"
      Days-Left: "1"
  18. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I have also tried float, i got it working using sql tho
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oh, that's because PHP would automatically change array keys to integers if all array keys are numeric.
  20. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Ohh that would make sence lol but I still don't get why I can't set that big of a integer as a key to yaml..maybe I got the 32 bit binarys by mistake?..I believe I var_dump php_int_max tho and it was the 64 bit max.

Share This Page

Advertisement