Syntactical differences between 123basic and GLBasic - metzzo/123-basic GitHub Wiki
All the changes to the 123basic syntax do not break backwards compability to GLB. All GLB source code can be compiled by the 123basic compiler.
Extended FOR Syntax
State: Implemented
Additionally to the classic FOR i = 0 TO 10
, 123basic supports a UNTIL version of this syntax FOR i = 0 UNTIL 10
, which does basically the same but excludes the last number (instead of 0-10 it goes 0-9). This is very helpful when iterating over an array or something similar but not intending to use "-1".
LOCAL arr[]
DIM arr[10]
// classic iterating
FOR i = 0 TO LEN(arr[]) - 1
STDOUT "i: "+arr[i]+"\n"
NEXT
// new iterating
FOR i = 0 UNTIL LEN(arr[]) // the -1 is not needed
STDOUT "i: "+arr[i]+"\n"
NEXT
Array brackets not needed
State: Implemented
When passing arrays as an argument to a function GLB needs you to use []
. 123basic does this automatically for you.
LOCAL arr[]
STDOUT LEN(arr[]) // classic
STDOUT LEN(arr) // new
Function brackets not always needed
State: Implemented
When calling a function , the brackets are not needed if the return value is not used. Same applies to FUNCTION in TYPEs or SUBs.
myAwesomeFunction // this is valid
// LOCAL whatIsTheAnswer = myAwesomeFunction // this is invalid, because the return value is used.
FUNCTION myAwesomeFunction:
RETURN 42 // answer for everything
ENDFUNCTION
OOP
State: Implemented
123basic takes the FUNCTION in TYPEs mechanic of GLBasic and takes it to a new level: Object Oriented Programming. Inheritance has been implemented, which allows easy translations of real world object structures into programming structures. Additionally there is the feature of method overloading and ABSTRACT methods, which are intended to extend the function of existing methods (FUNCTION in TYPEs in GLB).
TYPE Vehicle
X; Y
ABSTRACT FUNCTION Update: // this function is abstract, so no implementation required, but this also means, that if you extend a VEHICLE, you have to override this FUNCTION
FUNCTION Render:
DRAWRECT X, Y, 10, 10, RGB(255,0,0)
ENDFUNCTION
ENDTYPE
TYPE Car EXTENDS Vehicle
FUNCTION Update:
// driving logic here
ENDFUNCTION
FUNCTION Render:
DRAWRECT X+10,Y+10,100,100,RGB(0,0,255)
super.Render // super allows access to objects lower in the inheritance hiarchy
ENDFUNCTION
ENDTYPE
LOCAL c AS Car
LOCAL v AS Vehicle
v = c // valid, because a Car is always a Vehicle
// c = v // invalid, because a Vehicle is not required to be a car
c.Render // renders 2 rects
v.Render // throws runtime exception, because Vehicle is an abstract TYPE
HTML5/JS Limitations
- ALPHAMODE -X does the same as ALPHAMODE +X
- POLYVECTOR is slow and does not support gradients
- LOADSPRITE / LOADANIM is asynchronous, which means they are not available until GLB_ON_LOOP.
- Your main loop has to be in a
GLB_ON_LOOP
sub. Displaying a loading screen can be done withGLB_ON_LOADING
- Avoid
GOTO
/BYREF
/ALIAS
if performance is an issue. These features need to be emulated which is very slow. KEYWAIT
/MOUSEWAIT
is not supported by HTML5, because of the callback based nature of HTML5