10-18-2023, 10:55 PM
And this type of thing can catch you when you least expect it. Take a look at the glitchy code below:
Now, it's obvious that we're making an array that works on storing and changing our screen pixels. Screens are _Width -1, _Height -1 in size, so we make the array to be to that size... Nothing wrong with that. Right?
Except we didn't explicitly define the bounds of our array and *assumed* that it'd be BASE 0. With Option Base 1 in effect, we generate errors and crash.
Explicitly define your arrays in library codes. Don't assume the base you're used to working in is what the public you share your code with, is going to be using.
Code: (Select All)
'This is my Program code area
Screen _NewImage(1280, 720, 32)
$Color:32
Option Base 1
Cls , Red
Sleep
FadeDown Blue
Sleep
FadeDown Yellow
Sleep
FadeDown White
Sleep
FadeDown Black
''$INCLUDE:'my file holding the library stuff below:
Sub FadeDown (colour As _Unsigned Long)
Dim tempScreen(_Width - 1, _Height - 1) As _Unsigned Long
Dim fade As _Unsigned Long
For y = 0 To _Height - 1
fade = _RGBA32(255 * (y / _Height) * _Red32(colour), 255 * (y / _Height) * _Green32(colour), 255 * (y / _Height) * _Blue32(colour), 255 * (y / _Height))
For x = 0 To _Width - 1
tempScreen(x, y) = Point(x, y) And fade
Next
Next
For y = 0 To _Height - 1
fade = _RGBA32(_Red32(colour), _Green32(colour), _Blue32(colour), _Height / y * 255)
For x = 0 To _Width - 1
PSet (x, y), tempScreen(x, y)
Next
Next
End Sub
Now, it's obvious that we're making an array that works on storing and changing our screen pixels. Screens are _Width -1, _Height -1 in size, so we make the array to be to that size... Nothing wrong with that. Right?
Except we didn't explicitly define the bounds of our array and *assumed* that it'd be BASE 0. With Option Base 1 in effect, we generate errors and crash.
Explicitly define your arrays in library codes. Don't assume the base you're used to working in is what the public you share your code with, is going to be using.