Answer the question
In order to leave comments, you need to log in
How to programmatically implement a causal relationship?
Hello.
Let me know if I'm going in the right direction.
I argue on the example of the construction IF - THEN - ELSE.
IF event_occurs THEN command_1 ELSE command_0.
IF button_pressed THEN print_character ELSE just_wait.
Don't you think that on the example of a button, everything looks rather primitive.
If you also think so or you are sure, then let's figure out together how, what and where.
Namely, how to programmatically (competently) implement a causal relationship?
Answer the question
In order to leave comments, you need to log in
Well, callbacks are still being implemented. Slot signals. Events. But this is all, in fact, syntactic sugar around an ordinary IF.
The programmer always puts two glasses on the bedside table:
one full, in case he wants to drink, and the second empty, in case he does not want to.
Let's consider the option with the button. Let's say we have some function that returns the status of a button.
Waiting in the simplest case is an infinite loop.
while true
{
if (buttonPressed())
{
print('hello');
}
}
while true
{
if (buttonPressed())
{
print('hello');
}
sleep(300);
}
bool buttonReleased = true;
while true
{
if (buttonPressed())
if (buttonReleased)
{
print('hello');
buttonReleased = false;
}
else
buttonReleased = true;
sleep(300);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question