hey i need help. i am coding a Shop UI Plugin and now i have a big problem. My main file called Main.php and my shop file called Shop.php How can i connect these 2 files? In the Main file i had write the UI Basics (openShopForm) In the Shop File i had write the Shop form, but this form don't open. Thanks for help Good Day
You have to call it as an object and execute the function in the object. You also have to construct the object sufficiently. Here is an example of what I'm talking about: Let's say we have two classes: Class A, and Class B. In class A, I want to call a function from class B. In class A I would do something like this: PHP: class A extends PluginBase{public function openMenu(){ $menu = new ShopUI($this); $menu->openMenu($player);}} and Class B would look something like this: PHP: class B{private $plugin;public function __construct(PluginMainFile $plugin){ $this->plugin = $plugin}public function openMenu(Player $player){ // actions}} I suck at explaining, but you should search up on Google "PHP OOP" for more understanding.
Also I Must Write the Plugin so: Main.php class Main extends PluginBase implements Listener{ public function openMyForm($player) case 0; $this->openShopForm($player); Shop.php private $plugin; public function __construct(PluginMainFile $plugin){ $this->plugin = $plugin } public function openShopForm($player) Actions is it right or isn’t it?
Not really You see, the function "openShopForm" is in the Shop class and not in the Main class. Because "$this" refers to the current class/object, that code wouldn't work. Also, in Shop.php, in the function __construct, the "PluginMainFile" is supposed to be the name of the class that is constructing it. On top of that. I'm pretty sure you can't use "case" without using switch first Code: PHP: <?phpclass Main extends PluginBase implements Listener{ public function openMyForm(Player $player){ switvh($data){ // ? what is being switched here case 0: $shop = new ShopUI($this); $shop->openShopForm($player); break; } }}class ShopUI{ private $plugin; public function __construct(Main $plugin){ $this->plugin = $plugin; } public function openShopForm(Player $player){ // do your actions }}
[14:41:10] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\plugin\PluginBase::__construct() must implement interface pocketmine\plugin\PluginLoader, instance of black\Main given, called in phar:///home/minecraft/plugins/WordShop_1.3.4.phar/src/black/Main.php on line 110" (EXCEPTION) in "src/pocketmine/plugin/PluginBase" at line 77 help plss