PDA

View Full Version : How do I display bitmaps using functions in a global struct?


jonlauf
10-27-2006, 02:48 PM
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

HalfVector
10-27-2006, 02:58 PM
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...

handiklap
10-27-2006, 03:06 PM
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!

jonlauf
10-27-2006, 03:08 PM
Thanks Half Vector and handiklap, appreciate the help

CGTalk Moderation
10-27-2006, 03:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.