Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:48 10 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Problem with sprite(C)

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 01:42pm 05 Apr 2025
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 4854
Posted: 06:44am 06 Apr 2025
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 08:13pm 06 Apr 2025
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4251
Posted: 08:42pm 06 Apr 2025
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 12:32pm 07 Apr 2025
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4251
Posted: 01:12pm 07 Apr 2025
Copy link to clipboard 
Print this post

  William Leue said  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.


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: Canada
Posts: 499
Posted: 02:59pm 07 Apr 2025
Copy link to clipboard 
Print this post

Yep Tom, that error was a pain. At the end I just used an ON ERROR SKIP do avoid the problem  
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025