1. Help creating procedures

Hello all,

I am writng a program in DOS32 that displays bitmaps a lot and I am
attempting to write two procedures that will make this task easier to code.
My first procedure allows me to load a bitmap and display it at a certain
point on screen with one line of code:

procedure image(sequence name, integer x, integer y)

integer error
object bitmap

bitmap = read_bitmap(name & ".bmp")
error = sequence(bitmap)

if error = 0 then
    puts(1, "Error loading bitmap")
    abort(0)
else
    all_palette(bitmap[1] / 4)
    bitmap = bitmap[2]
    display_image({x,y}, bitmap)
end if

end procedure

Now I can call a bitmap and display it like so:
image("c:\\euphoria\\bitmaps\\test", 100, 100)

What I want to do now it have another procedure called address that would
allow me to list the address seperately and have image() use that each time
so that I do not have to type it repeatedly. Something like:

procedure address(sequence where_is_it)
end procedure

Used like so:

address("c:\\euphoria\\bitmaps\\")

My problem is that when I try to place where_is_it in procedure image() I am
informed that where_is_it has not been declared. I have been trying all
sorts of things but nothing solves the problem. This error is resulting
before the program even runs.

Any help?

Thank you,
David S.

new topic     » topic index » view message » categorize

2. Re: Help creating procedures

> > I am writng a program in DOS32 that displays bitmaps a lot and I am
> > attempting to write two procedures that will make this task 
> > easier to code.
> > My first procedure allows me to load a bitmap and display it 
> > at a certain
> > point on screen with one line of code:
> > 
> > procedure image(sequence name, integer x, integer y)
> > 
> > integer error
> > object bitmap
> > 
> > bitmap = read_bitmap(name & ".bmp")
> > error = sequence(bitmap)
> > 
> > if error = 0 then
> >     puts(1, "Error loading bitmap")
> >     abort(0)
> > else
> >     all_palette(bitmap[1] / 4)
> >     bitmap = bitmap[2]
> >     display_image({x,y}, bitmap)
> > end if
> > 
> > end procedure
> > 
> > Now I can call a bitmap and display it like so:
> > image("c:\\euphoria\\bitmaps\\test", 100, 100)
> > 
> > What I want to do now it have another procedure called 
> > address that would
> > allow me to list the address seperately and have image() use 
> > that each time
> > so that I do not have to type it repeatedly. Something like:
> > 
> > procedure address(sequence where_is_it)
> > end procedure
> > 
> > Used like so:
> > 
> > address("c:\\euphoria\\bitmaps\\")
> > 
> > My problem is that when I try to place where_is_it in 
> > procedure image() I am
> > informed that where_is_it has not been declared. I have been 
> > trying all
> > sorts of things but nothing solves the problem. This error is 
> > resulting
> > before the program even runs.
> 
> I suspect that the problem is that the "address" procedure has been defined
> after the "image" procedure. Euphoria is a bit simplistic in this regard,
> unlike some other languages. Euphoria can only use routines if it has
> already seen their definition earlier in the source code. 
> 
> Thus ...
>   procedure aa()
>   end procedure
 
>   procedure bb()
>      aa()
>   end procedure

> is okay ...


AND THIS IS OK TOO!

integer aa_int
            aa_int = 0
        
   procedure bb()
      call_proc(aa_int, {})
   end procedure
 
   procedure aa()
     bb()
   end procedure
   aa_int = routine_id("aa")
   
   aa() 
       or,
   bb()

Euman
euman at bellsouth.net


> But ......
 
>   procedure bb()
>   aa()
>   end procedure
 
>   procedure aa()
>  bb()
>  end procedure
   
>   aa()
 
 >is not okay. You may have to manually rearrange your source code so that
 >Euphoria stops complaining.
 
> -----------
> cheers,
> Derek Parnell
> Senior Design Engineer
> Global Technology Australasia Ltd
> dparnell at glotec.com.au
> 
> ---------------------

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

3. Re: Help creating procedures

On Thursday 19 July 2001 21:53, Derek Parnell wrote:

> I suspect that the problem is that the "address" procedure has been defined
> after the "image" procedure. Euphoria is a bit simplistic in this regard,
> unlike some other languages. Euphoria can only use routines if it has
> already seen their definition earlier in the source code.

I am always puzzled why this is a problem for anyone. 
Many languages require definitions of variables, functions and procedures
*before* they are called.  I may not always write my code in the order that 
it appears in the source file, but it's just a matter of hitting the page-up 
key a couple of times to put things where they belong.

To do otherwise is like my building a house for you, and after I'm finished,
learning how to cut lumber. 

Regards,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu