L
L
Lord_Dantes2020-01-31 12:03:28
PHP
Lord_Dantes, 2020-01-31 12:03:28

How can you change the value of a variable or implement a state machine?

I am writing a bot. I need to write a condition, if the user writes /help, a text appears to him + he expects any text from the user and does something with it.
I do it like this.
I declare a variable, let's say event_user, I assign 0 to it.
Then I check if the user writes / help, I assign event_user = 1 and send the text, ok it is.
Then I make a condition if event_user == 1, then any text that the user sends to the bot will be sent.
But as I understand it, I did not change the value of the event_user variable, because I do this already in my condition, those in my condition $ event_user == 1, is incorrect because it is initially 0.
Question: how can a variable be changed so that the value can be accepted on the condition further, or how can this be implemented without libraries?

the code

$event_user = 0;

if (mb_stripos($msg_txt, '/help') !== false){
    $event_user = 1;
    // send message
  } elseif ($event_user == 1){
   // send message
  }


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zudwa, 2020-01-31
@Lord_Dantes

Save the value of event_user in the database or, in extreme cases, in a file, because each time the bot is accessed in the script, $event_user = 0 will be executed; and elseif ($event_user == 1) will never hit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question