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

Using Command Parameters In Seperate Functions

Comments in 'Plugin Development' started by Comedyman937, Mar 17, 2014.

  1. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Hello,

    Im working on a plugin that will require me to use the API Schedules.
    My issue is that when i run the schedule (which starts after a command is sent) and it goes to the finction for after the time, it doesnt know the parameters that it neds anymore. Heres what i mean:

    PHP:
    public function CommandHandler($cmd$params$issuer$alias)
    {
         switch(
    strtolower($cmd))
         {
              case 
    "timercommand":
                   if(
    count($params) > || $params[0] == "help"){
                        return 
    "Usage: /timercommand <SECONDS> <COMMAND> <PLAYER>";
               }
                   
    $secs strtoupper($params[0]);
                   
    $cmd strtoupper($params[1]);
                   
    $player strtoupper($params[2]);
     
                   
    $this->api->schedule($secs*20, array($this"timer"));
         }
    }
    So obviously what this is doing is setting up the command that will be run after a set amount of time (in seconds) Now to show you where the issue starts...

    PHP:
    public function timer($cmd$params$issuer$alias)
    {
         if(isset(
    $player)){
              
    $this->api->console->run($cmd." ".$player);
         }else{
              
    $this->api->console->run($cmd);
         }
         
    console("[INFO] [TimerCommand] Command run sucesfully!");
    }
    The error i get from this is:
    Code:
    [ERROR] A E_WARNING error happened: "Missing argument 3 for TimerCommand::timer()" in "/private/var/PocketMine-MP/plugins/TimerCommand.php" at line 52
    [ERROR] A E_WARNING error happened: "Missing argument 4 for TimerCommand::timer()" in "/private/var/PocketMine-MP/plugins/TimerCommand.php" at line 52
    I have no idea why im getting this error... Could someone please help?

    Thanks!
    Last edited: Mar 17, 2014
  2. ZacHack
    Offline

    ZacHack Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    325
    Plugins:
    6
    Minecraft User:
    _ZacHack_
    It should look like this
    PHP:
                    $this->api->schedule(20, array($this"join"), array(), true);
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    To supply parameters in a scheduled function, you need this:
    PHP:
    $server->schedule($ticks$callable$anyParametersYouWantToPass$doYouWantToRepeatItAfter);
    function callable(
    $dataWhichIsTheThirdParameterAbove){
    }

Share This Page

Advertisement