Author Topic: Short scrip, yet it fails?  (Read 3113 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Short scrip, yet it fails?
« on: July 12, 2011, 03:44:53 am »
The thing is, there are 16 sprites defined as followed:
Code: [Select]
SpriteNumber .equ AppBackUpScreen
yspr1 .equ SpriteNumber+2
xspr1 .equ yspr1+1
yspr2 .equ xspr1+1
xspr2 .equ yspr2+1
yspr3 .equ xspr2+1
xspr3 .equ yspr3+1
yspr4 .equ xspr3+1
xspr4 .equ yspr4+1
yspr5 .equ xspr4+1
xspr5 .equ yspr5+1
;etc.

Now, there is the following piece of code, with input C = Xcoordinate of a sprite.
The idea is that it's loading C (thus an x-coordinate) to Sprite1, then Sprite2, then 3 etc. and after Sprite16 has been assigned, it starts over with Spr1 again. There's something glitchy, since it sometimes suddenly removes sprites from the screen (thus assigns x,y values to a sprite on the screen already). I can'tr figure out what's wrong though. Could it perhaps be because of direct input with the buttonpresses that it sometimes fails to finish this loop or something?

Script:

Code: [Select]
NextSprite:
LD hl, SpriteNumber
LD A, (SpriteNumber)
LD B, A
NextSpriteLoop:
INC HL                                ; 2x INC HL will go to the next sprite, since each HL holds X
INC HL                                ; and Y respectively of the current spritenumber
djnz NextSpriteLoop                    ; Keeps track of the current sprite
LD A, -9                             ; Set the Y position of the current sprite
LD (hl), A                            ; And save it to Sprite*number*
INC HL
LD (hl), C                            ; Save an X-coordinate to Sprite*number*
LD A, (SpriteNumber)
CP 16                                 ; After giving an X and Y to Sprite16, start with Sprite 1 again
JR Z, ResetSpriteNumber
INC A
LD (SpriteNumber), A
ret
ResetSpriteNumber:
LD A, 1
LD (SpriteNumber), A
ret

So... is there something wrong? Or are the errors caused by other factors?
Thanks!


79% of all statistics are made up randomly.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Short scrip, yet it fails?
« Reply #1 on: July 12, 2011, 11:51:14 am »
So, is it supposed to set the coordinates of the current sprite to (C,-9) and then make the next sprite the current one, and making the first one currrent if it just set the coordinates of the 16th sprite?
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Short scrip, yet it fails?
« Reply #2 on: July 16, 2011, 02:00:31 pm »
So, is it supposed to set the coordinates of the current sprite to (C,-9) and then make the next sprite the current one, and making the first one currrent if it just set the coordinates of the 16th sprite?
Yup.
So you "LD C, [x-coordinate] ", then call this and it should put spr.1 to those coordinates. Then spr.2 at the next call etc. untill it goes back to 1 after having set 16. But something's wrong, and it might be this script...
If not, the problem lies elsewhere and everyone's free to use this, lol.


79% of all statistics are made up randomly.