# Solved Need help with Scheduler

Comments in 'Plugin Development' started by cake23, Feb 8, 2016.

1. Offline

### cake23Active Member

Joined:
Aug 10, 2015
Posts:
124
Minecraft User:
Hey! I need help with the scheduleRepeatingTask!
Main-File:
PHP:
 <?phpnamespace SchedulerTest;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\Player;class Main extends PluginBase implements Listener {       public function onEnable() {        $this->getLogger()->info("activated!");$this->getServer()->getPluginManager()->registerEvents($this,$this);    }       public function onJoin(PlayerJoinEvent $event) {$player = $event->getPlayer();$this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), 20); } }  And the Task.php-File: PHP:  <?phpnamespace Task;use pocketmine\scheduler\PluginTask;use pocketmine\Server;use pocketmine\utils\TextFormat as Color;class Task extends PluginTask { public function __construct(\pocketmine\plugin\Plugin$owner) {        parent::__construct($owner);$this->owner = $owner; } public function onRun($currentTick) {        \$this->getOwner()->getServer()->getLogger()->info("Test!");    }   } 
And i get this Error:
Code:
[20:33:12] critical> "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'SchedulerTest v1.0.0': Class SchedulerTest\Task not found on SchedulerTest\Main

Can anyone help me? :/ I am sorry, i am new in creating a Task....
2. Offline

### HotFireyDeathNotable MemberPlugin Developer

Joined:
Mar 19, 2015
Posts:
328
Plugins:
1
Minecraft User:
Remember you need to import the namespace\to\your\task\file; namespace like you did the PocketMine namespaces.
cake23 likes this.
3. Offline

### cake23Active Member

Joined:
Aug 10, 2015
Posts:
124
Minecraft User:
So i need to change the namespace in my task.php-file to the same namespace in my main-file? (namespace SchedulerTest
4. Offline

### HotFireyDeathNotable MemberPlugin Developer

Joined:
Mar 19, 2015
Posts:
328
Plugins:
1
Minecraft User:
PHP:
 use namespace\to\task.php; 
Alternatively, you could include your Task class inside the main file, and avoid the complexity of a second PHP file.
cake23 likes this.
5. Offline

### cake23Active Member

Joined:
Aug 10, 2015
Posts:
124
Minecraft User:
Oh okay, thanks!
HotFireyDeath likes this.
6. Offline

### CraftYourBukkitNotable MemberPlugin Developer

Joined:
Jan 20, 2015
Posts:
1,022
Plugins:
2
Minecraft User:
Since when with ".php"?
cake23 likes this.
7. Offline

### HotFireyDeathNotable MemberPlugin Developer

Joined:
Mar 19, 2015
Posts:
328
Plugins:
1
Minecraft User:
My message "Namespace to task.php" does not imply that it must end with .php.
I said namespace to that specific file, so you would enter the corresponding namespace and not the file path.
cake23 likes this.
8. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
You should be thinking about the class name, not the file name.
HotFireyDeath and cake23 like this.