How do I return a boolean instead of locking up the process?
Shadowblitz16

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

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

why? its easy to read

SiegeLord
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;
}

?

Edgar Reynaldo

al_wait_for_event blocks until it gets an event. If you don't want to do that, use one of its cousins, al_get_next_event or al_wait_for_event_until.

You could also run your window in a thread and send an event to your main loop when the window closes. The window is running until you get the close event.

Thread #618438. Printed from Allegro.cc