I'm trying to use GENSPRITE() to make assigning numbers to sprites easier, but it just crashes my game.
If I do this:
GLOBAL menuPointerSprite = GENSPRITE()
LOADSPRITE "/Menu/pointer.png", menuPointerSprite
As indicated in the help file, the game compiles correctly, but when it runs I just get the spiny circle icon, and my app never appears. I have to go into Task Manager and kill it off.
I've also tried this:
GLOBAL menuPointerSprite = 0
menuPointerSprite = GENSPRITE()
LOADSPRITE "/Menu/pointer.png", menuPointerSprite
My game compiles and runs, but it always assigns 0 to menuPointerSprite.
For instance:
GLOBAL screenGrab = 0
screenGrab = GENSPRITE()
GLOBAL menuPointerSprite = 0
menuPointerSprite = GENSPRITE()
LOADSPRITE "/Menu/pointer.png", menuPointerSprite
PRINT screenGrab, 10,10
PRINT menuPointerSprite, 10,20
Shows me that both screenGrab and menuPointerSprite are equal to 0. I don't think I'm doing anything wrong (famous last words!)...
This is running under Windows 7 Ultimate, 64bit.
I don't think sprites are known by GENSPRITE() until they are actually allocated, such as using the LOADSPRITE() command. So both your GENSPRITE() commands return '0' because at the time you called them, no sprites where ever allocated.
So in your example, try:
GLOBAL screenGrab = 0
screenGrab = GENSPRITE()
LOADSPRITE "/Screen/grab.png", screenGrab // <- Must load sprite before calling next GENSPRITE()!!!
GLOBAL menuPointerSprite = 0
menuPointerSprite = GENSPRITE()
LOADSPRITE "/Menu/pointer.png", menuPointerSprite
PRINT screenGrab, 10,10
PRINT menuPointerSprite, 10,20
Nope, doesn't work. Both still print 0.
In fact, if I do this:
GLOBAL screenGrab = 1
screenGrab = GENSPRITE()
LOADSPRITE "/Menu/outer.png", screenGrab
GLOBAL menuPointerSprite = 2
menuPointerSprite = GENSPRITE()
LOADSPRITE "/Menu/pointer.png", menuPointerSprite
PRINT screenGrab, 10,10
PRINT menuPointerSprite, 10,20
It still prints 0 for both sprite numbers, so GENSPRITE isn't actually working.
There is no problem with GENSPRITE. Unfortunately, there is with your pathing.
Try this instead :
GLOBAL screenGrab = 1
screenGrab = GENSPRITE()
LOADSPRITE "./Menu/outer.png", screenGrab
GLOBAL menuPointerSprite = 2
menuPointerSprite = GENSPRITE()
LOADSPRITE "./Menu/pointer.png", menuPointerSprite
Oh, and the only command that can initialise variables is RGB
[attachment deleted by admin]
Then perhaps those paths to your .png files are wrong?
Did you try setting the current directory?:
SETCURRENTDIR("Media")
Yes, pathing is very important - GENSPRITE returns the next free slot. If a sprite can't be loaded, then the value wont be increased...
Ah yes, the pathing thing fixes it. Thanks :)
Quote from: MrTAToad on 2010-Sep-28
Oh, and the only command that can initialise variables is RGB
That's a change which needs to be made to the help file then, as it states:
GLOBAL gImgFoo = GENSPRITE(); LOADSPRITE "foo.png", gImgFoo
GLOBAL gImgBar = GENSPRITE(); LOADSPRITE "bar.png", gImgBar
DRAWSPRITE gImgFoo,0,0
DRAWSPRITE gImgBar,0,100
SHOWSCREEN
MOUSEWAIT
Yes, it does need changing.
I fixed that GLOBAL a=foo() for the next update. You can use _ANY_ functions now. The initialization is called right before __MainGameSub kicks in.
Quote from: Kitty Hello on 2010-Sep-30
I fixed that GLOBAL a=foo() for the next update. You can use _ANY_ functions now. The initialization is called right before __MainGameSub kicks in.
Wow, that's great news!
Will this let us call functions inside other function calls, such as:
LOCAL v1 as TVector
v1 = VectorAdd( VectorNew(1, 2, 3), VectorNew(4, 5, 6) )
Or could we before and I just didn't realize it?!
You could before - although if you aren't careful you'll end up with messy code.