invalid type conversion?
BlitzPlus Forums/BlitzPlus Programming/invalid type conversion?
| ||
Little problem with my current space shooter game...this is with the current BlitzPlus V1.37... I have a "snake" in the game...just a segmented set of sprites that moves around the screen...each segment is a instance of the same type with a Id flag indicateing if it's the snake head or just a body segment...I can get them moveing around and everything, no problem...but I want to draw the sprites in reverse order so that the head is drawn last... like so: s.snake = LAST snake REPEAT IF s\idflag = snakebody THEN DRAWIMAGE sbodimg, s\x, s\y ELSE DRAWIMAGE shedimg, s\x, s\y END IF s = BEFORE s UNTIL NOT s That won't even compile and I get the "Invalid type conversion" error indicateing at the keyword REPEAT However this works fine: FOR s.snake = EACH snake IF s\idflag = snakebody THEN DRAWIMAGE sbodimg, s\x, s\y ELSE DRAWIMAGE shedimg, s\x, s\y END IF NEXT So it's not the graphic image handles or type fields...what gives? |
| ||
I've just messed around with the code a bit, and it looks like the problem is at the "UNTIL NOT s," not sure why it reports it at the REPEAT. Anyways, the problem is you can't have "NOT s" (or just "s" in an expression for that matter). You need to find some other way to tell when you've cycled through all of the 'snakes.' EDIT: If your trying to cycle through the snakes backwards, I'd make a function to count how many snakes there are (CountSnakes()), then know to exit the repeat...until loop once you have iterated through the desired number of times. |
| ||
The correct way to check for the existence of a type object is with Null. When 's=Null' is true the object s does not exist. After fixing this the Repeat loop would still fail if the list is empty. You really should use a While loop. While s <> Null ; do stuff with s Wend |
| ||
DOH! *smacks self* ...Thanks a ton!... damn strange about it flagging the Repeat though :P |