Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How do I return a boolean instead of locking up the process?

This thread is locked; no one can reply to it. rss feed Print
How do I return a boolean instead of locking up the process?
Shadowblitz16
Member #16,818
March 2018

how do I return true here?

#SelectExpand
1bool window_is_running() 2{ 3 if (!window_initalized) return false; 4 5 bool redraw = true; 6 ALLEGRO_EVENT event; 7 8 al_start_timer(window_timer); 9 while(1) 10 { 11 //need to return true here instead of locking up 12 al_wait_for_event(window_queue, &event); 13 14 if(event.type == ALLEGRO_EVENT_TIMER) 15 redraw = true; 16 17 else if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)) 18 break; 19 } 20 21}

I wanted to make it so I can do..

#SelectExpand
2window_init(256,240,60,"my title"); 3while(window_is_running()) 4{ 5 //code here 6}

Peter Hull
Member #1,136
March 2001

Can you not

#SelectExpand
1window_init(256,240,60,"my title"); 2bool window_is_running = true; 3al_start_timer(window_timer); 4while(window_is_running) 5{ 6 7 bool redraw = true; 8 ALLEGRO_EVENT event; 9 10 al_wait_for_event(window_queue, &event); 11 12 if(event.type == ALLEGRO_EVENT_TIMER) 13 redraw = true; 14 else if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)) 15 window_is_running = false; 16 //code here 17}

Shadowblitz16
Member #16,818
March 2018

why? its easy to read

SiegeLord
Member #7,827
October 2006
avatar

bool window_is_running_var = true;

bool window_is_running()
{
    if (!window_initalized) return false;
    ALLEGRO_EVENT event;
    al_wait_for_event(window_queue, &event);
    if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE))
        window_is_running_var = false;
    return window_is_running_var;
}

?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: