Jump to content

[SOLVED] PHP-CLI issue


hunter_thom

Recommended Posts

I am building a PHP-CLI 'game' for converting binary/hex/decimal, to better your speed at converting between base number systems. I started on the game class, and created a little menu with user input for different game modes. If the user inputs invalid data, the script is supposed to say 'invalid' and ask for the input again. Then, as long as the data remains invalid, the user is continuously promted until the data is valid, whereas the correct method is called.

 

My issue is that when invalid data is input, the 'invalid, try again' message is displayed 3 times before the script stops for the user to try again. So instead of:

 

Invalid data. Mode: (here, waits for the user to input)

 

it says:

 

Invalid data. Mode:

Invalid data. Mode:

Invalid data. Mode: (here, waits for the user to input)

 

I have tried altering my loop a few different ways, to no avail. This is also my very first php-cli and so I am a bit of a newb when it comes to php-cli. The code is attached. I'm not worried about other portions of the code at this point; can anyone see what I am doing incorrectly that is looping this message three times instead of just displaying once?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/149740-solved-php-cli-issue/
Share on other sites

At this point, I am planning on creating an interface which does all the cli-game generalitites, and then build a class to implement it for any cli-game i plan to make. However, I am still stuck, because although I will be rewriting some of my code, I am not sure why this iterates the way it does. As I will be coding the interface to be able to handle invalid user requests, I will still eventually need to correct this. Any thoughts would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/149740-solved-php-cli-issue/#findComment-786702
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.