Example

SUB demo.... with CARS

5

was8bit 2022-06-25 07:04

Use controls to drive the red car


McPepic 2022-06-25 14:16

I use this trick a lot. It was definitely difficult for me when I started using LowRes because you can’t return a value from a sub program, which are basically like methods. Once I figured out that formal parameters were reference type, it made writing sub programs a lot more flexible. Nice demo! :)


was8bit 2022-06-25 17:51

Thanky :)


SP4CEBAR 2022-06-26 11:54

special ability: 41% diagonal speed boost!

the distance traveled by stepping one time in two directions is step_size * SQR(2) = step_size * 1.41...


SP4CEBAR 2022-06-26 12:02

@McPepic apparently you can even send arrays to a sub

DIM ARR(9)
FOR I=0 TO UBOUND(ARR)
  READ ARR(I)
NEXT I
DATA 9,8,7,6,5,4,3,2,1,0

CALL WHATSUB(ARR)

SUB WHATSUB(ARR)
  FOR I=0 TO UBOUND(ARR)
    PRINT ARR(I)
  NEXT I
END SUB


SP4CEBAR 2022-06-26 12:12

I drove the car so fast that it went off the screen

lol I just made the typo: "v=fast"
(v means velocity in physics) ("v" is near "f" and "=" is near "backspace")


was8bit 2022-06-26 14:15 (Edited)

Cool array trick...

... did you also know you can do
DIM ARR(9)
inside the SUB, then use the array in the SUB.. and, like all other variables created in the SUB, it isnt seen by your main code, and gets destroyed when the SUB ends..


SP4CEBAR 2022-06-27 20:51

I actually didn't know that, makes sense now that I think about it, thank you!


was8bit 2022-06-27 23:07

:)


Log in to reply.