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

Object to String and then Back? / Easiest way to stop Inventory

Comments in 'Plugin Development' started by Samueljh1, Apr 4, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Ok: i have a question:

    I have an object, and i want to save it. I do this, but saving an object to a yml causes a segmentation fault.

    Basically, what i am trying to do is save a player's inventory. using:

    PHP:
    $player->getInventory()->getContents();
    This returns an array containing pocketmine\item\Item objects.

    Like I said before, storing that array causes a segmentation fault. I tried to implode it, but i can't convert the objects back.

    Is there any way to do this?

    If not, is there any way to store an object, but not in the form of one? Thanks.

    Thanks in advance! :)
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Try serialize | unserialize.
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    tried, didn't work :eek:
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Want to convert it to an array with primitive data types? Just convert each Item into an array of array($id, $damage, $count) values with the slots as the keys. You can easily construct them back with Item::get() when you retrieve these items.

Share This Page

Advertisement