text stringlengths 0 721 |
|---|
Use for raycasting, sprite rotation, particle systems, any high-freq trig. |
--- |
## Command-Line Arguments |
```basic |
' bazzbasic.exe myprog.bas arg1 arg2 |
PRINT ARGCOUNT ' number of args (2 in this example) |
PRINT ARGS(0) ' first arg → "arg1" |
PRINT ARGS(1) ' second arg → "arg2" |
``` |
`ARGCOUNT` and `ARGS(n)` are 0-based; ARGS does not include the interpreter or script name. |
--- |
## Libraries & INCLUDE |
```basic |
INCLUDE "helpers.bas" ' Insert source at this point |
INCLUDE "MathLib.bb" ' Load compiled library |
' Compile library (functions only — no loose code) |
' bazzbasic.exe -lib MathLib.bas → MathLib.bb |
' Function names auto-prefixed: MATHLIB_functionname$ |
PRINT FN MATHLIB_add$(5, 3) |
``` |
Library functions can read main-program constants (`#`). `.bb` files are version-locked. |
--- |
## Passing Arrays to Functions |
Arrays cannot be passed directly to `DEF FN` functions, but a clean workaround exists using JSON serialization. Convert the array to a JSON string with `ASJSON`, pass the string as a parameter, then deserialize inside the function with `ASARRAY`. This is the accepted pattern in BazzBasic v1.2+. |
```basic |
DEF FN ProcessPlayer$(data$) |
DIM arr$ |
LET count$ = ASARRAY(arr$, data$) |
RETURN arr$("name") + " score:" + arr$("score") |
END DEF |
[inits] |
DIM player$ |
player$("name") = "Alice" |
player$("score") = 9999 |
player$("address,city") = "New York" |
[main] |
LET json$ = ASJSON(player$) |
PRINT FN ProcessPlayer$(json$) |
END |
``` |
**Notes:** |
- The function receives a full independent copy — changes inside do not affect the original array |
- Nested keys work normally: `arr$("address,city")` etc. |
- Overhead is similar to copying an array manually; acceptable for most use cases |
--- |
## Program Structure |
```basic |
' ---- 1. FUNCTIONS (or INCLUDE "functions.bas/bb") ---- |
DEF FN Clamp$(v$, lo$, hi$) |
IF v$ < lo$ THEN RETURN lo$ |
IF v$ > hi$ THEN RETURN hi$ |
RETURN v$ |
END DEF |
' ---- 2. INIT (declare ALL constants & variables here, not inside loops) ---- |
' Performance: variables declared outside loops avoid repeated existence checks. |
[inits] |
LET SCREEN_W# = 640 |
LET SCREEN_H# = 480 |
LET MAX_SPEED# = 5 |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game" |
LET x$ = 320 |
LET y$ = 240 |
LET running$ = TRUE |
' ---- 3. MAIN LOOP ---- |
[main] |
WHILE running$ |
IF INKEY = KEY_ESC# THEN running$ = FALSE |
GOSUB [sub:update] |
GOSUB [sub:draw] |
SLEEP 16 |
WEND |
SOUNDSTOPALL |
END ' place at the end of main program so BazzBasic wont fall to subs in runtime |
' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ---- |
[sub:update] |
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED# |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.