Notifications
Clear all

[Closed] How do I display bitmaps using functions in a global struct?

I’m trying to use bitmaps created in functions stored in a global struct for icons in a rollout, but I’m having trouble. The only way I can get it to work is if I define each bitmap as a global variable, which I’d like to avoid. Could someone explain to me why the following code does not work:

First piece of code defines a global struct with a function for creating a bitmap. It is evaluated first.


global mapTest
struct mapTest
(
fn newBitmap =
(
	pic = bitmap 14 14 color:red
)
)

Second code attempts to run the function and display the bitmap, but returns “No display function for undefined”


mapTest.newBitmap()
display pic

Thanks

3 Replies

Hi.

I guess the reason is “pic” is a local variable so it can’t be accessed externally (only in the function “newBitmap”). So the code should be:

struct mapTest
(
	fn newBitmap =
	(
		return (bitmap 14 14 color:red)
	)
)

pic = mapTest.newBitmap()
display pic

Or maybe I didn’t understand what you’re trying to do…

The functions in your struct (and any variables they initialize) are local by nature, so you have to return the bitmap instead of simply creating it, which would only define it in the scope of the struct. Try this:


    global mapTest
    struct mapTest
    (
    fn newBitmap =
    (
    	bitmap 14 14 color:red
    )
    )
    
    pic = mapTest.newBitmap()
    display pic

edit: arg beaten!

Thanks Half Vector and handiklap, appreciate the help