Answer the question
In order to leave comments, you need to log in
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?
$event_user = 0;
if (mb_stripos($msg_txt, '/help') !== false){
$event_user = 1;
// send message
} elseif ($event_user == 1){
// send message
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question