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

"Use" something?

Comments in 'Plugin Development' started by Legoboy0215, Jun 22, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Do I need to use something when I use array_mt_rand?
    For example:
    Code:
    use pocketmine\***\***;
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I believe that belongs to the PHP standard library, so... Nope.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Then what is this???
    Code:
    Call to undefined function myname\space\array_mt_rand()
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Try \array_mt_rand()
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Where should i put it? The code:
    Code:
        function \array_mt_rand(array $a){
      return $a[array_keys($a)[mt_rand(0, count($a) - 1)]];
        }
    ????
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Wait...
    If you are creating the function you need to access it from the class instance which contains it
    CrazedMiner likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    so if my classs is called main, then use myname\space\main;
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The method array_mt_rand() is not built-in in PHP. Who told you there is such method?

    P.S. I taught you how to define that function, but I never told you that you should use it in that exact way!
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Me??? You never taught me that? This is how it was defined:
    PHP:
    function array_mt_rand(array $a){
      return 
    $a[array_keys($a)[mt_rand(0count($a) - 1)]];
        }
    I am just helping my friend to bug test, so IDK a lot.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Where did you put that function in?
    Anyway, plugins are not encouraged to create namespace functions (instead of class functions). Put that code inside a class and call it with $this->array_mt_rand($a) instead.

Share This Page

Advertisement