CrashCore 1.16.0 Released!
Crash BASIC 1.16.0 Release Notes
written by Crash-tan
THE "POINTERS? IN MY BASIC?" RELEASE
Dereference Operator: &
The & operator lets you use a string as a variable name, function name, or dotted path — resolved at runtime. It's one character of indirection that opens up function pointers, dynamic variable access, and data-driven dispatch.
Read a variable by name:
score = 100
ref$ = "SCORE"
PRINT &ref$ ' prints 100Write to a variable by name:
ref$ = "SCORE"
&ref$ = 200 ' sets SCORE = 200Function pointers:
FUNCTION Add(a, b)
Add = a + b
END FUNCTION
FUNCTION Multiply(a, b)
Multiply = a * b
END FUNCTION
op$ = "ADD"
PRINT &op$(3, 4) ' prints 7
op$ = "MULTIPLY"
PRINT &op$(3, 4) ' prints 12CALL with deref:
handler$ = "OnClick"
CALL &handler$(x, y)Dynamic variable names in loops:
FOR i = 1 TO 5
ref$ = "SCORE" + STR$(i)
&ref$ = i * 100
NEXT i
' SCORE1=100, SCORE2=200, SCORE3=300, SCORE4=400, SCORE5=500Works with dotted paths — including namespace variables:
NAMESPACE Player
hp = 100
END NAMESPACE
ref$ = "PLAYER.HP"
PRINT &ref$ ' prints 100
&ref$ = 75 ' sets Player.hp to 75Works with namespaced functions:
NAMESPACE Math
FUNCTION Square(x)
Square = x * x
END FUNCTION
END NAMESPACE
ref$ = "MATH.SQUARE"
PRINT &ref$(7) ' prints 49Namespace Variable Scoping (Bug Fix)
Variables defined inside NAMESPACE blocks were not being scoped to their namespace. Two namespaces with the same variable name would stomp each other. Now variables are properly prefixed:
NAMESPACE Player
hp = 100
END NAMESPACE
NAMESPACE Enemy
hp = 50
END NAMESPACE
PRINT Player.hp ' 100
PRINT Enemy.hp ' 50 (was 50 before too, but only by accident — it was overwriting Player.hp)How it works:
- Variables created inside a namespace are stored with the namespace prefix (e.g.,
PLAYER.HP) - Reading from inside the namespace resolves the prefixed name automatically
- Reading from outside uses dot syntax:
Player.hp - Global variables defined outside any namespace are still accessible from inside namespaces
- Writing to a variable that already exists in an outer scope writes to the outer variable (no shadowing)
Also
- 39 new unit tests covering dereference (read, write, function call, CALL sub, dotted paths, namespaced functions/subs, dynamic names), namespace variable isolation, cross-namespace access, and global variable accessibility from within namespaces.