EkBass commited on
Commit
a31960f
·
verified ·
1 Parent(s): b080843

Update BazzBasic-AI-guide.txt

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide.txt +94 -255
BazzBasic-AI-guide.txt CHANGED
@@ -1,114 +1,70 @@
1
- # METADATA:
2
- **Name:** BazzBasic-AI-guide.txt
3
- **Description:** BazzBasic BASIC interpreter language reference for AI. Use BazzBasic to write, debug, or teach code.
4
- **File extensions:*** ".bas"*, *".bb"*
5
- **Version:** This guide is written for BazzBasic version 1.3 and is updated 11.04.26 (ddmmyy)
6
- **URL:** This guide is stored and updated at https://huggingface.co/datasets/EkBass/BazzBasic_AI_Guide
7
- # END METADATA
8
-
9
  ---
10
 
11
- ## BazzBasic details
12
- **Version:** 1.3
13
- **Author:** Kristian Virtanen (EkBass)
14
- **Platform:** Windows x64
15
- **License:** MIT
16
-
17
- ## BazzBasic www-references
18
- **Homepage:** https://ekbass.github.io/BazzBasic/
19
  **GitHub:** https://github.com/EkBass/BazzBasic
20
  **Manual:** https://ekbass.github.io/BazzBasic/manual/#/
21
- **Common examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
22
  **Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
23
- **Rosetta-Code examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples/rosetta-code
24
 
25
  ---
26
 
27
  ## ⚠️ Critical Rules — Read First
 
28
  | Rule | Detail |
29
  |------|--------|
30
- | Every variable must be introduced with LET exactly once before any use | LET <var> |
31
  | Variables end with `$` | `name$`, `score$`, `x$` |
32
- | Variables must describe purpose | no x$, tmp$, a$ unless loop index |
33
  | Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
34
  | Arrays declared with `DIM`, end with `$` | `DIM items$` |
35
  | First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
36
  | FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
37
- | Avoid GOTO | Supported only for historical reasons |
38
  | Functions defined **before** they are called | Put at top or INCLUDE |
39
  | Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
40
  | Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
41
- | Arrays **cannot** be passed to functions directly | Pass individual elements by value, or serialize with `ASJSON` and deserialize inside with `ASARRAY` — see *Passing Arrays to Functions* section |
42
  | Case-insensitive | `PRINT`, `print`, `Print` all work |
43
  | `+` operator does both add and concatenate | `"Hi" + " " + name$` |
44
  | Division always returns float | `10 / 3` → `3.333...` |
45
 
46
-
47
- ### Common AI Mistakes
48
- - forgetting LET
49
- - Mis-using LET/ROWCOUNT with arrays
50
- - using LET inside subs (wastes computing time, prefer [inits] section)
51
- - calling function before definition
52
- - not using return value from FN (if not other chance, use temp$ to get it)
53
- - passing arrays to functions
54
- - mixing $ and #
55
- - using LET on subs or loops
56
- - forgots to use SCREENLOCK/SCREENUNLOCK
57
- - Does not read: ## Performance Tips
58
-
59
  ---
60
 
61
- ## For context from the author:
62
- **About:** BazzBasic is built around one simple idea: starting programming should feel nice and even fun. Ease of learning, comfort of exploration and small but important moments of success. Just like the classic BASICs of decades past, but with a fresh and modern feel.
63
 
64
- **Story:** Although over the years, as my own skills have grown, I have moved on to more versatile and modern languages, BASIC has always been something that has been fun to try out many different things with. Sometimes it's great to just make a simple adventure game again, a lottery machine, a quiz, or even just those balls bouncing on the screen. BazzBasic was created with this in mind. I wanted to create a language that makes it easy for you to give free rein to your curiosity and program something. And when you finish your first little game, you may crave something bigger and better.
 
65
 
66
- *Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for: To arouse your curiosity.*
67
 
68
- - Kristian Virtanen (EkBass), author of BazzBasic
69
 
70
- ## IDE & CLI
 
71
 
72
- Run `BazzBasic.exe` without any arguments to open the IDE.
73
 
74
- ## Editor Features
75
 
76
- - **Syntax highlighting** for BazzBasic keywords
77
- - **Line numbers** for easy navigation
78
- - **Multiple tabs** for working with several files
79
 
80
- ## Keyboard Shortcuts & Menu Map
81
 
82
- | Menu | Shortcut | Action | CLI option |
83
- |----------|--------|--------|--------|
84
- | File | Ctrl+N | New file | BazzBasic.exe |
85
- | File | Ctrl+O | Open file | none |
86
- | File | Ctrl+S | Save file | none |
87
- | File | Ctrl+Shift+S | Save As | none |
88
- | File | Ctrl+W | Close tab | none |
89
- | File | Alt + F4 | Exit | none |
90
- | Edit | Ctrl+F | Find | none |
91
- | Edit | Ctrl+H | Replace | none |
92
- | Run | F5 | Run Program | BazzBasic.exe file.bas |
93
- | Run | none | Compile as Exe | BazzBasic.exe -exe file.bas |
94
- | Run | none | Compile as Library (.bb) | BazzBasic.exe -lib file.bas |
95
- | Help | none | About | BazzBasic.exe -v |
96
- | Help | none | Beginner's Guide[1] | BazzBasic.exe -guide[2] |
97
- | Help | none | Check For Updates[3] | BazzBasic.exe -checkupdates |
98
 
99
- **[1]** Opens [BazzBasic-Beginners-Guide/releases](https://github.com/EkBass/BazzBasic-Beginners-Guide/releases) in default www-browser.
100
- **[2]** *BazzBasic.exe -guide* and *BazzBasic.exe -help* both works.
101
- **[3]** Just informs about the update, will not perform it.
102
 
103
  ## Variables & Constants
104
 
105
  ```basic
106
- ' variables
107
- LET a$ ' Declare without value
108
- LET name$ = "Alice" ' String variable
109
- LET score$ = 0 ' Numeric variable
110
- LET x$, y$, z$ = 10 ' Multiple declaration
111
- ' x$ & y$ has value of 0 while z$ has 10
 
112
 
113
  **Compound assignment operators** (variables only — **not** allowed with `#` constants):
114
 
@@ -120,11 +76,6 @@ x$ /= 4 ' divide
120
  s$ += " World" ' string concatenation
121
  ```
122
 
123
- ' constants
124
- LET TITLE# = "My Game" ' String constant
125
- LET_VER# = 1.2 ' Numeric constant
126
- ```
127
-
128
  **Scope:** All main-code variables share one scope (even inside IF blocks).
129
  `DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
130
 
@@ -132,8 +83,8 @@ LET_VER# = 1.2 ' Numeric constant
132
 
133
  ### Built-in Constants
134
  - **Boolean:** `TRUE`, `FALSE`
135
- - **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e)
136
- - **System:** `PRG_ROOT#` (program base directory path), `BBVER#` (interpreter version as text, e.g. `"1.1"`)
137
  - **Keyboard:** `KEY_ESC#`, `KEY_ENTER#`, `KEY_SPACE#`, `KEY_UP#`, `KEY_DOWN#`, `KEY_LEFT#`, `KEY_RIGHT#`, `KEY_F1#`…`KEY_F12#`, `KEY_A#`…`KEY_Z#`, `KEY_0#`…`KEY_9#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, etc.
138
 
139
  ---
@@ -155,7 +106,7 @@ matrix$(0, 1) = "A2" ' Multi-dimensional
155
  | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
156
  | `DELKEY arr$(key)` | Remove one element |
157
  | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
158
- | `JOIN dest$, src1$, src2$` | Merge two arrays into dest$; src2$ keys overwrite src1$ on conflict |
159
 
160
  **Always check with `HASKEY` before reading uninitialized elements.**
161
 
@@ -173,7 +124,7 @@ ELSE
173
  PRINT "F"
174
  END IF ' ENDIF also works
175
 
176
- ' One-line IF
177
  IF lives$ = 0 THEN GOTO [game_over]
178
  IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
179
 
@@ -215,8 +166,8 @@ END ' Terminate program
215
  | `LINE INPUT "prompt", var$` | Read entire line with spaces |
216
  | `CLS` | Clear screen |
217
  | `LOCATE row, col` | Move cursor (1-based) |
218
- | `CURPOS("row")` | Returns current cursor row |
219
- | `CURPOS("col")` | Returns current cursor column |
220
  | `COLOR fg, bg` | Text colors (0–15 palette) |
221
  | `SHELL("cmd")` | Run shell command, returns output |
222
  | `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
@@ -311,8 +262,7 @@ FN Clamp$(5, 1, 10) ' ✗ ERROR — return value unused
311
  | `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
312
  | `MOD(a, b)` | Remainder |
313
  | `POW(base, exp)` | Power |
314
- | `RND(0)` | Random float 0.0 to <1.0 |
315
- | `RND(n)` | Random integer 0 to n-1 (n ≥ 1) |
316
  | `ROUND(n)` | Standard rounding |
317
  | `SGN(n)` | Sign: -1, 0, or 1 |
318
  | `SQR(n)` | Square root |
@@ -379,7 +329,7 @@ LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
379
  MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
380
 
381
  ' Transform
382
- MOVESHAPE RECT#, x, y ' Position by top-left point
383
  ROTATESHAPE RECT#, angle ' Degrees (absolute)
384
  SCALESHAPE RECT#, scale ' 1.0 = original size
385
  DRAWSHAPE RECT# ' Render to buffer
@@ -387,11 +337,13 @@ SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
387
  REMOVESHAPE RECT# ' Free memory (always clean up)
388
  ```
389
 
 
390
  ---
391
 
392
  ### Text Rendering (SDL2_ttf.dll required)
393
  #### DRAWSTRING & LOADFONT
394
 
 
395
  ```basic
396
  ' Default font (Arial)
397
  DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
@@ -413,7 +365,7 @@ LOADFONT
413
  ```basic
414
  ' LOADSOUND returns a stable integer handle — SDL2 manages the resource.
415
  ' The handle never changes; store it in a constant to protect it from accidental reassignment.
416
- LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV/MP3 recommended)
417
  SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
418
  SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
419
  SOUNDREPEAT(SND_JUMP#) ' Loop continuously
@@ -430,10 +382,10 @@ Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
430
  ```basic
431
  LET data$ = FileRead("file.txt") ' Read as string
432
  DIM cfg$ : LET cfg$ = FileRead("settings.txt") ' Read as key=value array
433
- FILEWRITE "save.txt", data$ ' Create/overwrite
434
- FILEAPPEND "log.txt", entry$ ' Append
435
  LET ok$ = FileExists("file.txt") ' 1=exists, 0=not
436
- FILEDELETE "temp.dat" ' Delete file
437
  ```
438
 
439
  **key=value parsing:** When `FileRead` assigns to a `DIM`'d array, lines `key=value` become `arr$("key")`. Lines starting with `#` are comments. Perfect for `.env` files.
@@ -484,35 +436,6 @@ SAVEJSON arr$, "file.json"
484
 
485
  ---
486
 
487
- ## Passing Arrays to Functions
488
-
489
- Arrays cannot be passed directly to `DEF FN` functions. The accepted workaround (v1.2+) is JSON serialization: convert the array to a JSON string with `ASJSON`, pass it as a string parameter, then deserialize inside the function with `ASARRAY`.
490
-
491
- ```basic
492
- DEF FN ProcessPlayer$(data$)
493
- DIM arr$
494
- LET count$ = ASARRAY(arr$, data$)
495
- RETURN arr$("name") + " score:" + arr$("score")
496
- END DEF
497
-
498
- [inits]
499
- DIM player$
500
- player$("name") = "Alice"
501
- player$("score") = 9999
502
- player$("address,city") = "New York"
503
-
504
- [main]
505
- LET json$ = ASJSON(player$)
506
- PRINT FN ProcessPlayer$(json$)
507
- END
508
- ```
509
-
510
- - The function gets a full independent copy — changes do not affect the original array
511
- - Nested keys work normally: `arr$("address,city")` etc.
512
- - Overhead is comparable to manually copying an array
513
-
514
- ---
515
-
516
  ## Fast Trigonometry
517
 
518
  ~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
@@ -558,6 +481,36 @@ Library functions can read main-program constants (`#`). `.bb` files are version
558
 
559
  ---
560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
  ## Program Structure
562
 
563
  ```basic
@@ -568,18 +521,19 @@ DEF FN Clamp$(v$, lo$, hi$)
568
  RETURN v$
569
  END DEF
570
 
571
- ' ---- 2. INIT (declare ALL variables/constants here, not inside loops) ----
572
  ' Performance: variables declared outside loops avoid repeated existence checks.
573
  [inits]
574
- LET SCREEN_W# = 640
575
- LET SCREEN_H# = 480
576
- LET MAX_SPEED# = 5
 
 
 
577
  LET x$ = 320
578
  LET y$ = 240
579
  LET running$ = TRUE
580
 
581
- SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
582
-
583
  ' ---- 3. MAIN LOOP ----
584
  [main]
585
  WHILE running$
@@ -589,7 +543,7 @@ END DEF
589
  SLEEP 16
590
  WEND
591
  SOUNDSTOPALL
592
- END ' always before code enters to subroutines
593
 
594
  ' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ----
595
  [sub:update]
@@ -609,7 +563,7 @@ RETURN
609
  - Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
610
  - Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
611
  - Image/sound/shape IDs are stable integer handles — **always** store as constants: `LET MY_IMG# = LOADIMAGE("x.png")` — never use `$` variables for these
612
- - Group many IDs -> use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` — but prefer named constants when count is small
613
 
614
  ---
615
 
@@ -624,138 +578,23 @@ RETURN
624
 
625
  ---
626
 
627
- ## Rosetta-Code examples
628
-
629
- ### Animate a pendulum
630
 
 
 
631
  ```basic
632
- ' https://rosettacode.org/wiki/Animate_a_pendulum
633
- ' BazzBasic conversion from Freebasic code
634
  ' https://ekbass.github.io/BazzBasic/
635
-
636
- ' This is done for educational purposes -> commented everything
637
- ' Public Domain
638
-
639
-
640
- [inits]
641
- LET SCREEN_W# = 640 ' Screen width in pixels
642
- LET SCREEN_H# = 480 ' Screen height in pixels
643
- LET DAMPING# = 0.9995 ' Energy loss per frame (1.0 = no loss, 0.0 = instant stop)
644
-
645
- LET g$ = 9.81 ' Gravity constant (m/s²) — drives the swing force
646
- LET l$ = 1 ' Pendulum length (affects swing speed — longer = slower)
647
- LET speed$ = 0 ' Current angular velocity (how fast the angle is changing)
648
- LET accel$ ' Angular acceleration this frame (force pushing toward center)
649
-
650
- LET px$ = SCREEN_W# / 2 ' Pivot point X — where the pendulum is attached (screen center top)
651
- LET py$ = 10 ' Pivot point Y — a bit down from top edge
652
- LET theta$ = HPI# ' Current angle in radians (HPI# = 90° = starts horizontal)
653
- LET bx$ ' Bob X position on screen (calculated each frame)
654
- LET by$ ' Bob Y position on screen (calculated each frame)
655
-
656
-
657
- [main]
658
- SCREEN SCREEN_W#, SCREEN_H#
659
- WHILE INKEY <> KEY_ESC#
660
- ' Project angle to screen coordinates
661
- bx$ = px$ + l$ * (SCREEN_W# / 2) * SIN(theta$) ' horizontal offset from pivot
662
- by$ = py$ - l$ * (SCREEN_W# / 2) * COS(theta$) ' vertical offset from pivot (Y flipped)
663
-
664
- SCREENLOCK ON
665
- LINE (0, 0) - (SCREEN_W#, SCREEN_H#), 15, BF ' clear screen
666
- LINE (px$, py$) - (bx$, by$), 0 ' draw rod
667
- CIRCLE (bx$, by$), 50, 7, 1 ' draw bob
668
- SCREENLOCK OFF
669
-
670
- accel$ = g$ * SIN(theta$) / l$ / 100 ' gravity pulls bob toward center (SIN of angle = sideways force)
671
- speed$ = (speed$ * DAMPING#) + accel$ / 100 ' update speed with damping applied
672
- theta$ = theta$ + speed$ ' advance the angle by current speed
673
- SLEEP 16
674
- WEND
675
- END
676
  ```
677
 
678
- ### RGB attributes generator
679
- ```basic
680
- ' ============================================
681
- ' https://rosettacode.org/wiki/RPG_attributes_generator
682
- ' BazzBasic: https://github.com/EkBass/BazzBasic
683
- ' ============================================
684
- ' Attributes: Strength, Dexterity, Constitution,
685
- ' Intelligence, Wisdom, Charisma
686
- '
687
- ' Rules:
688
- ' - Total of all attributes must be >= 75
689
- ' - At least two attributes must be >= 15
690
-
691
- LET MIN_TOTAL# = 75
692
- LET MIN_TWO# = 15
693
-
694
- ' Roll 4d6, drop the lowest die, return sum of top 3
695
- DEF FN RollStat$()
696
- LET r1$ = RND(6) + 1
697
- LET r2$ = RND(6) + 1
698
- LET r3$ = RND(6) + 1
699
- LET r4$ = RND(6) + 1
700
- RETURN r1$ + r2$ + r3$ + r4$ - MIN(MIN(r1$, r2$), MIN(r3$, r4$))
701
- END DEF
702
 
703
- [inits]
704
- DIM attributes$
705
- attributes$("str") = 0
706
- attributes$("dex") = 0
707
- attributes$("con") = 0
708
- attributes$("int") = 0
709
- attributes$("wis") = 0
710
- attributes$("cha") = 0
711
- LET stat$ = 0
712
- LET total$ = 0
713
- LET highCount$ = 0
714
- LET passed$ = FALSE
715
-
716
- [main]
717
- WHILE passed$ = FALSE
718
- stat$ = FN RollStat$() : attributes$("str") = stat$
719
- stat$ = FN RollStat$() : attributes$("dex") = stat$
720
- stat$ = FN RollStat$() : attributes$("con") = stat$
721
- stat$ = FN RollStat$() : attributes$("int") = stat$
722
- stat$ = FN RollStat$() : attributes$("wis") = stat$
723
- stat$ = FN RollStat$() : attributes$("cha") = stat$
724
-
725
- total$ = attributes$("str") + attributes$("dex") + attributes$("con") + attributes$("int") + attributes$("wis") + attributes$("cha")
726
-
727
- highCount$ = 0
728
- IF attributes$("str") >= MIN_TWO# THEN highCount$ = highCount$ + 1
729
- IF attributes$("dex") >= MIN_TWO# THEN highCount$ = highCount$ + 1
730
- IF attributes$("con") >= MIN_TWO# THEN highCount$ = highCount$ + 1
731
- IF attributes$("int") >= MIN_TWO# THEN highCount$ = highCount$ + 1
732
- IF attributes$("wis") >= MIN_TWO# THEN highCount$ = highCount$ + 1
733
- IF attributes$("cha") >= MIN_TWO# THEN highCount$ = highCount$ + 1
734
-
735
- IF total$ >= MIN_TOTAL# AND highCount$ >= 2 THEN passed$ = TRUE
736
- WEND
737
-
738
- PRINT "Attribute Score"
739
- PRINT "------------------"
740
- PRINT "Strength " + STR(attributes$("str"))
741
- PRINT "Dexterity " + STR(attributes$("dex"))
742
- PRINT "Constitution " + STR(attributes$("con"))
743
- PRINT "Intelligence " + STR(attributes$("int"))
744
- PRINT "Wisdom " + STR(attributes$("wis"))
745
- PRINT "Charisma " + STR(attributes$("cha"))
746
- PRINT "------------------"
747
- PRINT "Total " + STR(total$)
748
- END
749
 
750
- ' Expected output (example - varies each run):
751
- ' Attribute Score
752
- ' ------------------
753
- ' Strength 13
754
- ' Dexterity 15
755
- ' Constitution 12
756
- ' Intelligence 11
757
- ' Wisdom 15
758
- ' Charisma 10
759
- ' ------------------
760
- ' Total 76
761
- ```
 
1
+ ---
2
+ name: bazzbasic
3
+ description: "BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on: BazzBasic syntax, $ and # variable suffixes, SDL2 graphics in BASIC, SCREEN/DRAWSHAPE/LOADIMAGE commands, DEF FN functions, BazzBasic file I/O, sound commands, or any question about BazzBasic features. Always use this skill before writing any BazzBasic code."
 
 
 
 
 
4
  ---
5
 
6
+ # BazzBasic Language Reference
7
+ **Version:** 1.3 | **Author:** Kristian Virtanen (EkBass) | **Platform:** Windows x64
 
 
 
 
 
 
8
  **GitHub:** https://github.com/EkBass/BazzBasic
9
  **Manual:** https://ekbass.github.io/BazzBasic/manual/#/
10
+ **Examples:** https://github.com/EkBass/BazzBasic/tree/main/Examples
11
  **Rosetta Code:** https://rosettacode.org/wiki/Category:BazzBasic
12
+
13
 
14
  ---
15
 
16
  ## ⚠️ Critical Rules — Read First
17
+
18
  | Rule | Detail |
19
  |------|--------|
 
20
  | Variables end with `$` | `name$`, `score$`, `x$` |
 
21
  | Constants end with `#` | `MAX#`, `PI#`, `TITLE#` |
22
  | Arrays declared with `DIM`, end with `$` | `DIM items$` |
23
  | First use of variable requires `LET` | `LET x$ = 0` — after that `x$ = x$ + 1` |
24
  | FOR and INPUT auto-declare, no LET needed | `FOR i$ = 1 TO 10` |
 
25
  | Functions defined **before** they are called | Put at top or INCLUDE |
26
  | Function name ends with `$`, called with `FN` | `FN MyFunc$(a$, b$)` |
27
  | Function return value **must** be used | `PRINT FN f$()` or `LET v$ = FN f$()` |
28
+ | Arrays **cannot** be passed to functions directly | Pass individual elements, or serialize to JSON string — see *Passing Arrays to Functions* section |
29
  | Case-insensitive | `PRINT`, `print`, `Print` all work |
30
  | `+` operator does both add and concatenate | `"Hi" + " " + name$` |
31
  | Division always returns float | `10 / 3` → `3.333...` |
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ---
34
 
 
 
35
 
36
+ ## ABOUT
37
+ BazzBasic is built around one simple idea: starting programming should feel nice and even fun.
38
 
39
+ Ease of learning, comfort of exploration and small but important moments of success.
40
 
41
+ Just like the classic BASICs of decades past, but with a fresh and modern feel.
42
 
43
+ ## STORY
44
+ Although over the years, as my own skills have grown, I have moved on to more versatile and modern languages, BASIC has always been something that has been fun to try out many different things with.
45
 
46
+ Sometimes it's great to just make a simple adventure game again, a lottery machine, a quiz, or even just those balls bouncing on the screen.
47
 
48
+ BazzBasic was created with this in mind.
49
 
50
+ I wanted to create a language that makes it easy for you to give free rein to your curiosity and program something.
 
 
51
 
52
+ And when you finish your first little game, you may crave something bigger and better.
53
 
54
+ Maybe one day you will move on to another programming language, but then BazzBasic will have succeeded in doing what it was intended for.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ To arouse your curiosity.
 
 
57
 
58
  ## Variables & Constants
59
 
60
  ```basic
61
+ LET a$ ' Declare without value
62
+ LET name$ = "Alice" ' String variable
63
+ LET score$ = 0 ' Numeric variable
64
+ LET x$, y$, z$ = 10 ' Multiple declaration
65
+ LET PI# = 3.14159 ' Constant (immutable)
66
+ LET TITLE# = "My Game" ' String constant
67
+ ```
68
 
69
  **Compound assignment operators** (variables only — **not** allowed with `#` constants):
70
 
 
76
  s$ += " World" ' string concatenation
77
  ```
78
 
 
 
 
 
 
79
  **Scope:** All main-code variables share one scope (even inside IF blocks).
80
  `DEF FN` functions are fully isolated — only global constants (`#`) accessible inside.
81
 
 
83
 
84
  ### Built-in Constants
85
  - **Boolean:** `TRUE`, `FALSE`
86
+ - **Math:** `PI#`, `HPI#` (π/2 = 90°), `QPI#` (π/4 = 45°), `TAU#` (2π = 360°), `EULER#` (e) — `#` suffix required
87
+ - **System:** `PRG_ROOT#` (program base directory path)
88
  - **Keyboard:** `KEY_ESC#`, `KEY_ENTER#`, `KEY_SPACE#`, `KEY_UP#`, `KEY_DOWN#`, `KEY_LEFT#`, `KEY_RIGHT#`, `KEY_F1#`…`KEY_F12#`, `KEY_A#`…`KEY_Z#`, `KEY_0#`…`KEY_9#`, `KEY_LSHIFT#`, `KEY_LCTRL#`, etc.
89
 
90
  ---
 
106
  | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
107
  | `DELKEY arr$(key)` | Remove one element |
108
  | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
109
+ | `JOIN dest$, src1$, src2$` | Merge two arrays; `src2$` keys overwrite `src1$`. Use empty `src1$` as `COPYARRAY`. |
110
 
111
  **Always check with `HASKEY` before reading uninitialized elements.**
112
 
 
124
  PRINT "F"
125
  END IF ' ENDIF also works
126
 
127
+ ' One-line IF (GOTO/GOSUB only)
128
  IF lives$ = 0 THEN GOTO [game_over]
129
  IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [play]
130
 
 
166
  | `LINE INPUT "prompt", var$` | Read entire line with spaces |
167
  | `CLS` | Clear screen |
168
  | `LOCATE row, col` | Move cursor (1-based) |
169
+ | `CURPOS("row")` / `CURPOS("col")` | Read cursor row or col (1-based, matches LOCATE) |
170
+ | `CURPOS()` | Read cursor as `"row,col"` string |
171
  | `COLOR fg, bg` | Text colors (0–15 palette) |
172
  | `SHELL("cmd")` | Run shell command, returns output |
173
  | `SHELL("cmd", ms)` | With timeout in ms (default 5000) |
 
262
  | `MAX(a, b)` / `MIN(a, b)` | Larger / smaller of two |
263
  | `MOD(a, b)` | Remainder |
264
  | `POW(base, exp)` | Power |
265
+ | `RND(n)` | Random integer 0 to n-1 |
 
266
  | `ROUND(n)` | Standard rounding |
267
  | `SGN(n)` | Sign: -1, 0, or 1 |
268
  | `SQR(n)` | Square root |
 
329
  MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
330
 
331
  ' Transform
332
+ MOVESHAPE RECT#, x, y ' Position by center point
333
  ROTATESHAPE RECT#, angle ' Degrees (absolute)
334
  SCALESHAPE RECT#, scale ' 1.0 = original size
335
  DRAWSHAPE RECT# ' Render to buffer
 
337
  REMOVESHAPE RECT# ' Free memory (always clean up)
338
  ```
339
 
340
+
341
  ---
342
 
343
  ### Text Rendering (SDL2_ttf.dll required)
344
  #### DRAWSTRING & LOADFONT
345
 
346
+
347
  ```basic
348
  ' Default font (Arial)
349
  DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
 
365
  ```basic
366
  ' LOADSOUND returns a stable integer handle — SDL2 manages the resource.
367
  ' The handle never changes; store it in a constant to protect it from accidental reassignment.
368
+ LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
369
  SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
370
  SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
371
  SOUNDREPEAT(SND_JUMP#) ' Loop continuously
 
382
  ```basic
383
  LET data$ = FileRead("file.txt") ' Read as string
384
  DIM cfg$ : LET cfg$ = FileRead("settings.txt") ' Read as key=value array
385
+ FileWrite "save.txt", data$ ' Create/overwrite
386
+ FileAppend "log.txt", entry$ ' Append
387
  LET ok$ = FileExists("file.txt") ' 1=exists, 0=not
388
+ FileDelete "temp.dat" ' Delete file
389
  ```
390
 
391
  **key=value parsing:** When `FileRead` assigns to a `DIM`'d array, lines `key=value` become `arr$("key")`. Lines starting with `#` are comments. Perfect for `.env` files.
 
436
 
437
  ---
438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
  ## Fast Trigonometry
440
 
441
  ~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory.
 
481
 
482
  ---
483
 
484
+ ## Passing Arrays to Functions
485
+
486
+ 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+.
487
+
488
+ ```basic
489
+ DEF FN ProcessPlayer$(data$)
490
+ DIM arr$
491
+ LET count$ = ASARRAY(arr$, data$)
492
+ RETURN arr$("name") + " score:" + arr$("score")
493
+ END DEF
494
+
495
+ [inits]
496
+ DIM player$
497
+ player$("name") = "Alice"
498
+ player$("score") = 9999
499
+ player$("address,city") = "New York"
500
+
501
+ [main]
502
+ LET json$ = ASJSON(player$)
503
+ PRINT FN ProcessPlayer$(json$)
504
+ END
505
+ ```
506
+
507
+ **Notes:**
508
+ - The function receives a full independent copy — changes inside do not affect the original array
509
+ - Nested keys work normally: `arr$("address,city")` etc.
510
+ - Overhead is similar to copying an array manually; acceptable for most use cases
511
+
512
+ ---
513
+
514
  ## Program Structure
515
 
516
  ```basic
 
521
  RETURN v$
522
  END DEF
523
 
524
+ ' ---- 2. INIT (declare ALL constants & variables here, not inside loops) ----
525
  ' Performance: variables declared outside loops avoid repeated existence checks.
526
  [inits]
527
+ LET SCREEN_W# = 640
528
+ LET SCREEN_H# = 480
529
+ LET MAX_SPEED# = 5
530
+
531
+ SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game"
532
+
533
  LET x$ = 320
534
  LET y$ = 240
535
  LET running$ = TRUE
536
 
 
 
537
  ' ---- 3. MAIN LOOP ----
538
  [main]
539
  WHILE running$
 
543
  SLEEP 16
544
  WEND
545
  SOUNDSTOPALL
546
+ END
547
 
548
  ' ---- 4. SUBROUTINES (or INCLUDE "subs.bas") ----
549
  [sub:update]
 
563
  - Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$`
564
  - Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines
565
  - Image/sound/shape IDs are stable integer handles — **always** store as constants: `LET MY_IMG# = LOADIMAGE("x.png")` — never use `$` variables for these
566
+ - Group many IDs use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` — but prefer named constants when count is small
567
 
568
  ---
569
 
 
578
 
579
  ---
580
 
581
+ ## IDE Features (v1.3)
 
 
582
 
583
+ ### New File Template
584
+ When the IDE opens with no file (or a new file), this template is auto-inserted:
585
  ```basic
586
+ ' BazzBasic version 1.3
 
587
  ' https://ekbass.github.io/BazzBasic/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  ```
589
 
590
+ ### Beginner's Guide
591
+ - **IDE:** Menu → **Help** → **Beginner's Guide** — opens `https://github.com/EkBass/BazzBasic-Beginners-Guide/releases` in default browser
592
+ - **CLI:** `bazzbasic.exe -guide` or `bazzbasic.exe -help` — prints URL to terminal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
 
594
+ ### Check for Updates
595
+ - **IDE:** Menu → **Help** → **Check for updated...** — IDE reports if a newer version is available
596
+ - **CLI:** `bazzbasic.exe -checkupdate`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
 
598
+ ### Compile via IDE
599
+ - **Menu → Run → Compile as Exe** — compiles open file to standalone `.exe` (auto-saves first)
600
+ - **Menu → Run → Compile as Library (.bb)** — compiles open file as reusable `.bb` library (auto-saves first)