1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

true false config

Discussion in 'Facepalm' started by Zoom601, Jun 18, 2017.

  1. Zoom601

    Zoom601 Silverfish

    Messages:
    21
    How can I make config if it is thing true doing something and if it is false doing something?

    like:
    keepinventory: true
    keepinventory: false

    :)
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    First, learn about Configs. I suggest Jack Noordhuis' tutorial. You already know about if/else statements, right? If you don't, try this resource. After that, you should be more than capable of doing this.
     
  3. Zoom601

    Zoom601 Silverfish

    Messages:
    21
    I know how to make config but I want to know how to do true and false config, can you explain more to me?
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    any of these can be used and YAML will output as a bool:
    Code:
    y|Y|yes|Yes|YES|n|N|no|No|NO
    |true|True|TRUE|false|False|FALSE
    |on|On|ON|off|Off|OFF
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    i don't understand xD
     
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    The best way to find out how something works is by experimenting yourself, then you will learn and understand how it functions as well as the limitations.
    PHP:
    $config = new pocketmine\utils\Config("https://gist.githubusercontent.com/JackNoordhuis/22d188eb1be819ab24d834bb4d4d5ef3/raw/e048e20254cdc828b62d06b0830f353fb81341dc/random-values.yml"pocketmine\utils\Config::YAML);
    if(
    $config->get("bool-value")) { # result will be true
        
    echo "true!\n";
    } else {
        echo 
    "false!\n";
    }

    if(
    $config->get("bool-value-2")) { # result will be false
        
    echo "true!\n";
    } else {
        echo 
    "false!\n";
    }
    /* @var $data array **/
    $data $config->getAll();
    if(
    $data["bool-value-3"] and !$data["bool-value-4"]) { # result will be true
        
    echo "true!\n";
    } else {
        echo 
    "false!\n";
    }

    if(
    $config->getNested("nested-values.nested-value")) { # result will be false
        
    echo "true!\n";
    } else {
        echo 
    "false!\n";
    }

    if(
    $data["nested-values"]["nested-value-2"]) { # result will be true
        
    echo "true!\n";
    } else {
        echo 
    "false!\n";
    }
    Code:
    true!
    false!
    true!
    false!
    true!
    
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.