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

$args variable

Comments in 'Plugin Development' started by RekkuzaRage, May 7, 2015.

  1. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    I been seeing the args variable mainly in commands. It seems like it is related to arrays. Can someone explain the args variable.
  2. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Read the PHP manual and you'll find it there.
    iJoshuaHD likes this.
  3. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    That isn't much help. Could you at least give me a brief explanation of it? How it functions and is used in PocketMine.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    The $args variable, in the context of commands, typically refers to an array of arguments passed to the command. Take the following command for example:

    Code:
    /time set day
    The contents of $args would be

    PHP:
    ["set""day"]
    So we could do

    PHP:
    $args[0]; // "set"
    $args[1]; // "day"

    Variable names are arbitrary, not all variables called "args" will be argument arrays and not all argument arrays will be called "args". I think this answers your question though.
    RekkuzaRage, Pman1220 and LDX like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Supplementary reading: http://php.net/manual/en/functions.arguments.php
    RekkuzaRage likes this.
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    In PocketMine $args is the array of all command arguments.
    Don't confuse $args with $argv. They are two different things. In fact $argv is the array of all command line arguments of PHP CLI
    RekkuzaRage, Falk and PEMapModder like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Except global variables (you won't use them in PocketMine plugins) and $this, all other variables are defined and named by yourself. Usually the first occurrence in a function defines it.
  8. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Stop asking for direct descriptions and try to find the answers.
  9. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    I was asking for a direct description, one of main points of creating this thread. Yeah, I also looked around Google trying to find answers, I didn't really understand what args meant even by looking on php.net, so I asked the PocketMine community. What's your problem with that?
    PEMapModder likes this.
  10. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Simple. $args is not predefined. It is defined by you. $args is the name of the array. Refer to @Falk's example earlier.
    RekkuzaRage likes this.
  11. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    251
    Minecraft User:
    RekkuzaRage
    Ik, I saw the posts earlier. Thanks anyways.

Share This Page

Advertisement