![]() |
Forum Index : Microcontroller and PC projects : Problem with sprite(C)
Author | Message | ||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
I don't know if this is one of my usual mistakes or whether it is a problem with MMBasic 5.07. When I do sn% = 9 a% = sprite(C, sn%, 1) I get the error message "Error in line xxx: 1 is invalid (valid is 0 to 1) -Bill |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4854 |
Hi Bill, Assume this is CMM2 ? When I read the manual correct, there can be multiple collisions with a sprite. Each of them can cause a collisions. So the sn% value tops at the number of actual collisions at that particular moment. Setting sn% to 9 means that you are sure there are 9 collisions at that moment. Meaning you have at least 10 sprites on screen. Again, just reading the manual, and having zero experience with CMM2. Volhout PicomiteVGA PETSCII ROBOTS |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Thanks, Volhout. However, I don't think that is correct. The manual says: SPRITE(C, (#)n, m) Returns the number of the sprite which caused the "m"th collision of sprite n. In my case I have more than 9 sprites and I want to know the number of the sprite that collided with my sprite #9. So I set n = 9 and m = 1, because there will never be more than 1 collision at a time. -Bill |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
I suspect the error message is rubbish and the issue is that that the sprite is involved in 0 collisions and thus there is no collision 1. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Tom, that makes sense. I wish this had been implemented better in MMBasic: I would prefer it to return zero if there were no collisions instead of erroring. Now I will have to bracket it with a 'on error skip' statement, which wastes time in a time-critical part of the code. -Bill |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
I had much the same thought when porting/rewriting this code for MMB4L but ultimately decided I had to maintain the existing behaviour. A related issue is that if you use SPRITE(C, #n) to get the number of collisions and then read and handle them using SPRITE(C, #n, m) then things get screwy if in handling a collision you actually resolve it such that the collision is no longer happening; the 'm' indexes all shift down one because of the removal of a collision. @LeoNicolas saw this in his `Knightmare` port ... I think I improved his code slightly in this area (or broke it in a different way), but I still may have ended up deploying ON ERROR SKIP. If you are reading Peter then maybe in the next version something like the command: SPRITE COLLISIONS #n, num, collisions() might prove more flexible. On return: `num` - the number of collisions sprite #n is involved in. `collisions` - the numbers of the other sprites/screen boundaries that sprite #n is collided with. If this array is too small then either ERROR or just fill it up to the number of available elements. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 499 |
Yep Tom, that error was a pain. At the end I just used an ON ERROR SKIP do avoid the problem ![]() |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |