1. Allegro Wrapper Help

Hello,

I am trying to make a wrapper example of the keyboard example that is found on the Allegro 5 API wiki. I think I have the code right, but it is not working correctly. Anyone help and notice if I'm doing something wrong?

without warning 
 
include std/machine.e 
include EuAllegro.ew 
 
atom ret = al_install_system(ALLEGRO_VERSION_INT,0) 
 
atom display = 0 
atom event = 0 
atom key = 0 
 
display = al_create_display(800,600) 
 
event = al_create_event_queue() 
 
key = al_install_keyboard() 
 
al_register_event_source(event,al_get_display_event_source(display)) 
 
atom run = 1 
 
al_flip_display() 
 
--program should end when ESC is pressed, but it does not happen 
while run = 1 do 
	al_wait_for_event(event,0) 
	 
	if key = ALLEGRO_KEY_ESCAPE then 
		run = 0 
	end if 
	 
end while 

https://wiki.allegro.cc/index.php?title=Basic_Keyboard_Example -The link to the keyboard example

Any help is appericated.

new topic     » topic index » view message » categorize

2. Re: Allegro Wrapper Help

Icy_Viking said...

Hello,

I am trying to make a wrapper example of the keyboard example that is found on the Allegro 5 API wiki. I think I have the code right, but it is not working correctly. Anyone help and notice if I'm doing something wrong?

 
--program should end when ESC is pressed, but it does not happen 
while run = 1 do 
	al_wait_for_event(event,0) 
	 
	if key = ALLEGRO_KEY_ESCAPE then 
		run = 0 
	end if 
	 
end while 

https://wiki.allegro.cc/index.php?title=Basic_Keyboard_Example -The link to the keyboard example

Any help is appericated.

You are testing 'key' for a new value but it is not being assigned anywhere within the loop..

Spock

new topic     » goto parent     » topic index » view message » categorize

3. Re: Allegro Wrapper Help

 
include std/machine.e 
include EuAllegro.ew 
 
atom ret = al_install_system(ALLEGRO_VERSION_INT,0) 
 
atom display = 0 
atom event = 0 
atom key = 0 
 
display = al_create_display(800,600) 
 
event = al_create_event_queue() 
 
key = al_install_keyboard() 
 
al_register_event_source(event,al_get_display_event_source(display)) 
 
atom run = 1 
 
al_flip_display() 
 
while run = 1 do 
	key = 0 
	al_wait_for_event(event,0) 
	 
	if key = ALLEGRO_KEY_ESCAPE then 
		run = 0 
	end if 
	 
end while 

I tried assigning the key variable inside the loop and it still does nothing. Am I skipping or missing a part?

new topic     » goto parent     » topic index » view message » categorize

4. Re: Allegro Wrapper Help

Icy_Viking said...
While run = 1 do 
	key = 0 
	al_wait_for_event(event,0) 
	 
	if key = ALLEGRO_KEY_ESCAPE then 
		run = 0 
	end if 
	 
end while 

I tried assigning the key variable inside the loop and it still does nothing. Am I skipping or missing a part?

You must assign key with the function that returns a keyboard code. Try to find such a function in the Allegro wrapper (the Eu file that links to Allegro) and change the assignment to, eg:

key = get_allegro_key()

I don't what the correct function name is but you should not have too much trouble finding it in the comments or documentation.

Spock

new topic     » goto parent     » topic index » view message » categorize

5. Re: Allegro Wrapper Help

This quick hack worked for me, though I couldn't find any layout structures. I figured out the ev+20 from dumps, which is not exactly ideal.

atom display = 0  
atom event = 0  
atom key = 0  
  
display = al_create_display(800,600)  
  
event = al_create_event_queue()  
  
--key = al_install_keyboard()  
if not al_install_keyboard() then ?9/0 end if 
  
--al_register_event_source(event,al_get_display_event_source(display))  
al_register_event_source(event,al_get_keyboard_event_source()) 
 
atom run = 1  
  
al_flip_display()  
 
atom ev = allocate(512)     -- should be big enough... 
 
--program should end when ESC is pressed, but it does not happen  
while run = 1 do  
--      al_wait_for_event(event,0)  
        al_wait_for_event(event,ev)  
          
        if peek4s(ev)=ALLEGRO_EVENT_KEY_DOWN then 
            key = peek4s(ev+20) 
            if key = ALLEGRO_KEY_ESCAPE then  
                run = 0  
            end if  
        end if 
          
end while  

Edit: I just found if key(KEY_ESC) then which may be what you are looking for? - oh, no, that's a much older version...

new topic     » goto parent     » topic index » view message » categorize

6. Re: Allegro Wrapper Help

petelomax said...

This quick hack worked for me, though I couldn't find any layout structures. I figured out the ev+20 from dumps, which is not exactly ideal.

atom display = 0  
atom event = 0  
atom key = 0  
  
display = al_create_display(800,600)  
  
event = al_create_event_queue()  
  
--key = al_install_keyboard()  
if not al_install_keyboard() then ?9/0 end if 
  
--al_register_event_source(event,al_get_display_event_source(display))  
al_register_event_source(event,al_get_keyboard_event_source()) 
 
atom run = 1  
  
al_flip_display()  
 
atom ev = allocate(512)     -- should be big enough... 
 
--program should end when ESC is pressed, but it does not happen  
while run = 1 do  
--      al_wait_for_event(event,0)  
        al_wait_for_event(event,ev)  
          
        if peek4s(ev)=ALLEGRO_EVENT_KEY_DOWN then 
            key = peek4s(ev+20) 
            if key = ALLEGRO_KEY_ESCAPE then  
                run = 0  
            end if  
        end if 
          
end while  

Edit: I just found if key(KEY_ESC) then which may be what you are looking for? - oh, no, that's a much older version...

Thanks it worked. This "hack" is probably the more Euphoria way to make this kinds of programs.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu