Posted 11 September 2013 - 06:49 AM
(correct capitalization is NextBASIC. Forum is stupid)
Pastebin code: XechUbLP
This is a simple BASIC dialect written in Lua for CC.
There are no loops or functions, only single-line IF and GOTO. This is intentional to keep the number of language features down. Arrays are a future possibility.
Commands do not have to be in uppercase. Variable names are case insensitive (XYZ and xyz are the same variable)
String variables have names ending in $, number variables do not.
Supported commands:
LET variable = value - sets a variable.
PRINT something - prints text or numbers. See the example program for examples of the various ways you can use PRINT.
INPUT variable - gets input from the user. Works for both number and string variables.
IF condition THEN command - runs command if condition is true. See example program for examples of how to use this.
[label] - a label that GOTO can go to.
GOTO [label] - jumps to a label.
CLS - clears the screen
REM anything - does nothing (this is a comment)
WAIT value SECONDS - waits a certain amount of time
SET REDSTONE SIGNAL side ON/OFF - sets a redstone signal output
SET REDSTONE SIGNAL side colour ON/OFF - sets a bundled redstone signal output
WAIT FOR REDSTONE SIGNAL side ON/OFF - waits for a redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL side colour ON/OFF - waits for a bundled redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL CHANGE - waits for any redstone input to change
INT(number) - equivalent to math.floor in Lua, rounds a number down to the nearest integer.
RND() - random number between 0 and 1
VAL(string) - converts a string to a number
STR$(number) - converts a number to a string
LEN(number) - the length of a string
LEFT$(string, number) - a certain number of characters from the start of a string
RIGHT$(string, number) - a certain number of characters from the end of a string
MID$(string, start, length) - a certain number of characters from the middle of a string. start is the position of the first character to get.
LOWER$(string) - converts a string to lowercase
UPPER$(string) - converts a string to uppercase
TRIM$(string) - removes spaces from the start and end of a string
INSTR(string to look in, string to look for, start position) - the position where one string occurs in another, or -1 if not found. Example: INSTR("hello world", "lo", 1) is 4. Always starts looking at start position.
< > <> <= >= = - comparison operators (respectively: greater than, less than, not equal, less than or equal, greater than or equal, equal)
X AND Y - true if X and Y are true
X OR Y - true if X or Y or both are true
NOT X - true if X is not true
REDSTONE SIGNAL side - true if there is a redstone signal input on side
REDSTONE SIGNAL side colour - true if there is a bundled signal input on side, wire colour colour
Example program (number guessing game):
Pastebin code: XechUbLP
This is a simple BASIC dialect written in Lua for CC.
There are no loops or functions, only single-line IF and GOTO. This is intentional to keep the number of language features down. Arrays are a future possibility.
Commands do not have to be in uppercase. Variable names are case insensitive (XYZ and xyz are the same variable)
String variables have names ending in $, number variables do not.
Supported commands:
LET variable = value - sets a variable.
PRINT something - prints text or numbers. See the example program for examples of the various ways you can use PRINT.
INPUT variable - gets input from the user. Works for both number and string variables.
IF condition THEN command - runs command if condition is true. See example program for examples of how to use this.
[label] - a label that GOTO can go to.
GOTO [label] - jumps to a label.
CLS - clears the screen
REM anything - does nothing (this is a comment)
WAIT value SECONDS - waits a certain amount of time
SET REDSTONE SIGNAL side ON/OFF - sets a redstone signal output
SET REDSTONE SIGNAL side colour ON/OFF - sets a bundled redstone signal output
WAIT FOR REDSTONE SIGNAL side ON/OFF - waits for a redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL side colour ON/OFF - waits for a bundled redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL CHANGE - waits for any redstone input to change
INT(number) - equivalent to math.floor in Lua, rounds a number down to the nearest integer.
RND() - random number between 0 and 1
VAL(string) - converts a string to a number
STR$(number) - converts a number to a string
LEN(number) - the length of a string
LEFT$(string, number) - a certain number of characters from the start of a string
RIGHT$(string, number) - a certain number of characters from the end of a string
MID$(string, start, length) - a certain number of characters from the middle of a string. start is the position of the first character to get.
LOWER$(string) - converts a string to lowercase
UPPER$(string) - converts a string to uppercase
TRIM$(string) - removes spaces from the start and end of a string
INSTR(string to look in, string to look for, start position) - the position where one string occurs in another, or -1 if not found. Example: INSTR("hello world", "lo", 1) is 4. Always starts looking at start position.
< > <> <= >= = - comparison operators (respectively: greater than, less than, not equal, less than or equal, greater than or equal, equal)
X AND Y - true if X and Y are true
X OR Y - true if X or Y or both are true
NOT X - true if X is not true
REDSTONE SIGNAL side - true if there is a redstone signal input on side
REDSTONE SIGNAL side colour - true if there is a bundled signal input on side, wire colour colour
Example program (number guessing game):
LET NumberOfGames = 0
LET NGuesses = 0
PRINT "What's your name? ";
INPUT name$
PRINT "Hi ";NAME$;"!"
IF INSTR(UPPER$(NAME$), "A", 1) <> -1 THEN PRINT "I see your name has an A in it."
PRINT
[difficulty]
PRINT "Select difficulty level - enter EASY, HARD or INSANE: ";
INPUT SEL$
LET SEL$ = UPPER$(SEL$)
IF SEL$ = "EASY" THEN LET MAX = 10:GOTO [startgame]
IF SEL$ = "HARD" THEN LET MAX = 100:GOTO [startgame]
IF SEL$ = "INSANE" THEN LET MAX = 10000:GOTO [startgame]
CLS
PRINT "That's not a valid answer, silly ";name$;"!"
GOTO [difficulty]
[startgame]
LET G = INT(RND() * MAX + 1)
PRINT
PRINT "=== GAME IS STARTING ==="
[enternumber]
PRINT "Enter a number between 1 and ";MAX;": ";
INPUT A
LET NGuesses = nguesses + 1
IF A < G THEN PRINT "Too low!"
IF A > G THEN PRINT "Too high!"
IF A <> G THEN GOTO [enternumber]
LET NumberOfGames = NumberOfGames + 1
PRINT "That's right!"
PRINT "You have won: ";NumberOfGames;" games in ";nguesses;" guesses, ";name$
GOTO [startgame]