Jump to content
IGNORED

Why does this code crash


Recommended Posts

This bit of code prints the variable value for I and Y, as the joystick is moved left, right, up, and down. It all works fine, until moving the joystick up, decreasing Y. As the Y variable value decreases eventually the program crashes. I'm using Altirra 3.1.

 

10 I=10:Y=12
100 STK=PEEK(54016)
110 IF STK=247 THEN POKE SCREEN+I+20*Y,0:I=I+0.1:IF I>=18 THEN I=18
120 IF STK=251 THEN POKE SCREEN+I+20*Y,0:I=I-0.1:IF I<=1 THEN I=1
130 IF STK=254 THEN POKE SCREEN+I+20*Y,0:Y=Y-0.1:IF Y<=1 THEN Y=1
140 IF STK=253 THEN POKE SCREEN+I+20*Y,0:Y=Y+0.1:IF Y>=22 THEN Y=22
150 PRINT I,Y
160 GOTO 100

 

Link to comment
Share on other sites

Where is defined SCREEN variable? It's not defined so it's value is zero so you are poking zero value in address area of 21-458 (zero page with OS/BASIC variables, page one - stack etc.). No wonder it crashes ;)

Edited by MaPa
Link to comment
Share on other sites

I missed including this line in the small program:

5 SCREEN=PEEK(88)+256*PEEK(89)

 

Once I included that the little program did not crash (thanks). This was to test something I tried in my larger program to slow the character down as it moves with the joystick. The game is a graphic mode 1 with redefined characters like many in the old Compute! magazines.

 

The actual program increases and decreases I and Y by 1 to move the character one space. I tried to slow the moving down by increasing I and Y by 0.5. It worked for left and right, but going up and down the character takes large jumps to the left or right. The the little program was to see what I and Y were doing as I moved the joystick. With the little program moving up and down (Y) did not change the value of "I" (left and right), as I expected it was doing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...