Hi, How do i make a system when player click the button and it queues him example: say that i clicked a button then if other player click the button then we two gonna go to a world then we gonna pvp like queuing system. I don't gonna go to the world unless someone click it to join the game since we two need to pvp. Just like practice pvp game and when i clicked the button the it will show like this Queued: 1/2 When someone clicked the button (not me) Then it will show Queued: 2/2 or Ongoing, then we gonna go to a specific world and fight
You could use arrays. I'm starting to forget PHP, so I might be incorrect. Example: PHP: public array $queued = [];/*** Queues a player** @param string $playername**/public function queuePlayer(string $playername) : void { if(empty($this->queued[])) { # If no one's in the queue $this->queued[] = $playername; # Set the player to the queue return; } # If someone is already in the queue $codeToStartTheGame; # Start the game unset($this->queued[]); # Clears the queue return;}// On Button Click# $player instance of Player object$this->queuePlayer($player->getName()); # Queues the player with the above function
You mis-spelt param as parem, and I think the rest is just fine — The student becomes the master , jk I’m a newbie
Its seems like its T_Public so i removed public now its T_Variable btw how do i got the counts of in queue
You can use a basic php function called count. Usage: PHP: count($array) This is to get the number of names in an array. PHP: count($this->queued[])
You don’t put a function inside a function. You don’t define a class variable inside a function. If you would like I can link you a website to learn php.
I’ll link them anyway. W3Schools OOP: https://www.w3schools.com/php/php_oop_what_is.asp TutorialPoint: https://www.tutorialspoint.com/php/php_object_oriented.htm