Category:Craft Basic

From Rosetta Code
(Redirected from Craft Basic)
This page is a stub. It needs more information! You can help Rosetta Code by filling it in!
Language
Craft Basic
This programming language may be used to instruct a computer to perform a task.
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using Craft Basic.

Craft Basic homepage

About:

Craft Basic is a BASIC interpreter for Windows 95 and up.

Tested on 95, XP, and 10.

* learn programming
* make simple games
* write code interactively
* perform complex calculations
* display cool graphics
* build windows with forms
* write useful scripts
* and more...

Memory:

Maximum lines of code is 10000.
Maximum operands in an expression is 200.
Maximum variables is 500.
Maximum arrays is 500 with 1000 maximum elements each.
Maximum declared functions is 100.

Expressions:

Operator precedence is !, *, /, %, +, -, <, >, <=, >=, =, <>, XOR, AND, OR, ^
AND may be written as &.
OR may be written as |.
XOR may be written as ~.
! is the not operator.
% is the mod operator.
^ is the power operator.
Functions have no precedence over any operators.
Floating point numbers are supported.
The negative operator is supported.
Parentheses may be used to override order of operations.
White space is optional.

Variables:

Variables and arrays are double precision.

Variable names a-z are pre defined.
All other variable names may consist of numbers and letters only.
Define variables by using let varname=0 with 0 as any value.
The define command may be used to bulk let commands together.
Omit the let and Use commas to separate the definitions.

Define arrays by using dim arrayname[arraysize].
The arraysize can be a variable or value.
Arrays are zero indexed and may only be one dimension.

Custom Defined Functions:

Define functions with the define command.
Function definitions may be mixed in with variable definitions.
All definitions are separated by commas.
Functions are a customizable array of expression strings.
Functions may be named similarly to variables.
Function names must be written in parenthesis without space between.
Functions are artery, but may use global variables.

The functions may be used anywhere in expressions.
The return value is the evaluation of the function string.

There's no precedence for custom functions.
Functions may only be defined once. More than once wastes memory.

Pre Defined Functions:

There are artery and unary pre defined functions.

Artery functions must be written in parenthesis without space between.

Unary functions must have a colon in front of it without space between.
Unary functions pass whatever comes in front of it as a parameter.

Pre defined functions have no precedence.
Precedence must be established with parenthesis for unary functions.
Wrap the unary function and it's parameter in parenthesis when needed.
This way, full expressions may be used as parameters for the function.

For example, let x=int:10/3 works fine, but not if int:(rnd)*3 = 1 then.
It must be written as if (int:(rnd)*3)=1 then.

Syntax:

Input may optionally have a prompt with double quotes, comma, variable.
Arrays and functions may be used wherever expressions are used.
Arrays may by used with the input and button commands.

Output may be combined in print, alert, and title using commas.
Output may include numbers, expressions, and double quoted text.
Output may also include the word comma to display a comma.

Distribution:

Craft Basic may be used as a scripting language by associating .bas files.
If you prefer to distribute the program as an .exe, follow these steps.
First, copy and paste Craft Basic.exe to the distribution directory.
Then copy your programs .bas file to the same directory.
Rename Craft Basic.exe to match the .bas file.
Change the .bas file extension to a .run file.
The result should look like myprogram.exe and myprogram.run.
When you run the resulting exe, your program will execute automatically.
Now you may include a readme and zip it up.

Known issues:

For some reason, -2^2 doesn't evaluate correctly.
If you hold down ctrl R for a long time, the program will crash.

Want to help fix an issue? Found a new problem?

Contact me at: ptrworkmails@gmail.com

Language keywords:

DEFINE variable=expression,variable=expression,variable=expression,etc...
DEFINE FN (FUNCNAME) AS expression,FN (FUNCNAME) AS expression,FN (FUNCNAME) AS expression, etc...
(short command: DEF)

IF expression THEN LABELNAME
(if short command: ?)

IF expression THEN
ENDIF
(endif short command: ??)

DO
LOOP expression
(loops while condition is true)
(loop with no parameter for an infinite loop)

LET variable=expression
(short command: #)


DIM variable[variable OR literal number]

PRINT expression OR comma OR "TEXT"
(short command: @)
(use commas to combine outputs)
(use the word comma between commas to display commas)

INPUT "PROMPT",variable
(short command: IN)
(the prompt is optional)

GOTO LABELNAME
(short command: .)

LABEL LABELNAME

GOSUB SUBNAME
(short command: ..)

SUB SUBNAME

RETURN
(short command: ...)

TITLE expression OR comma OR "TEXT"

ALERT expression OR comma OR "TEXT""
(short command: @@)

BUTTON variable,BUTTON CODE
(short command: BTN)

DRAWBMP FILE.BMP,expression,expression
(short command: BMP)
(don't use quotes in the filename)

PLAYWAV FILE.WAV
(short command: WAV)
(don't use quotes in the filename)

CURSOR expression,expression
(short command: CR)

RESIZE expression,expression,expression,expression

CENTER

DOT expression,expression

LINE expression,expression,expression,expression

OVAL expression,expression,expression,expression

RECT expression,expression,expression,expression

FGCOLOR expression,expression,expression
(short command: FG)

BGCOLOR expression,expression,expression
(short command: BG)

FILL ON/OFF

WAIT
(short command: WT)

CLS
(short command: X)

GETHDC
(use before drawing commands)

RELHDC
(use after drawing commands/after GETHDC calls)

MASK OF/OFF
(drawing transparency. defaults to off)

BUTTONFORM expression, expression, expression, expression
(generate new button form with specified coordinates and size)
(use formid to select the form handle)
(use formtext to prepare the form text)

STATICFORM expression, expression, expression, expression
(generate new static form with specified coordinates and size)
(use formid to select the form handle)

(use formtext to prepare the form text)

UPDATEFORM
(applies formtext to selected formid)

COLORFORM
(applies the last set foreground and background colors to the selected formid)

FORMID expression
(set the id to be used by form commands)

FORMTEXT expression OR comma OR "TEXT"
(set the text to be used by form commands)

RUN "windowsprogram.exe","windowsparameters",comma,expression,comma etc.....
(the first parameter is the program to run)
(the following parameters are formatted like print and combined)

END

REM
(short command: ')

(CLOCK)
(function returns milliseconds since boot)
(must include the parentheses without spaces)

(RND)
(function returns random number)
(must include the parentheses without spaces)

(MOUSEX)
(function returns mouse x coordinate relative to window)
(must include the parentheses without spaces)

(MOUSEY)
(function returns mouse t coordinate relative to window)

(MOUSEB)
(function returns 1 if left mouse button is pressed or 2 for right)
(returns 0 when no mouse button is clicked)

(FORMS)
(function returns id of any form that has been clicked)
(returns 0 when no form is clicked)

ABS:
(function returns absolute value of whatever comes after the colon)

INT:
(function returns integer of whatever comes after the colon)

SQRT:
(function returns square root of whatever comes after the colon)

SIN:
(function returns sine of whatever comes after the colon)

COS:
(function returns cosine of whatever comes after the colon)

TAN:
(function returns tangent of whatever comes after the colon)

ATN:
(function returns arctangent of whatever comes after the colon)

LOG:
(function returns logarithm of whatever comes after the colon)