This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-12-07 20:21:08

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

ZBasic

Guide to ZBasic 2.0

A (loose) collaboration by Rick3137 and MoreGamesNow

Please note, this guide is for ZBasic 2.0.  This means that it is out of date for ZBasic 2.1 (also known as MGN 2.1beta).  Version 2.1 supports drawing on a canvas, printing text, strings, getting input, and has a different notation for arrays.  If you're interested in 2.1 notation, simply view the project here.  Rick3137 offers code that shows examples of most, if not all, of the possible commands.  This will hopefully be updated to fit the latest version.

To set a variable:

Code:

a=3

- "a" is the variable name, and it sets it to the number 3
- It is important to note that, as of now, ZBasic doesn't support strings
- you may place expressions where the 3 is

To set an array length:

Code:

lista(7)

- this creates seven elements in list/array "a".
- you MUST do this before setting or reading an array element.
- you may place expressions within the parentheses

To print a variable

Code:

pnta

- prints the value of variable "a"
- you may place expressions where "a" is

To go back to another line (can be used with the if-statement to make a "loop"

Code:

GoTo8

- Sends the program back to line 8 and runs line 8, then line 9, 10, etc.
- You may NOT place expressions or variables here

If-else statement

Code:

if(a=2)
code here
}
else
code here
}

- Your basic if-statement.  The else is optional, just be sure to close your statements with "}"
- If you fail to close your statements, there will be a compiler error.

Code In Context

Code:

a=1
if(a=1)
a=2
GoTo2
}
else
pnta
}

should print "2".

To set an array element:

Code:

a[5]=5

******************************************

Added commands (2.1beta)

Summary:
- stop command
- print text command
- input
- setx1,setx2,sety1, sety2
- line
- wait,clear,square
- For/Next loop

Stop command

Code:

stop

Kills the program.  This was added to aid in debugging.

---------------------------------------------------------------

Code:

Print$

Prints the text following it verbatim

---------------------------------------------------------------

input command asks the user for input and assigns a variable to hold the input

Code:

inputa

sets a to the user's input

---------------------------------------------------------------

setx1,setx2,sety1, and sety2 give the canvas points to draw lines or squares.  line and square simply render either a line or a square based off of the points.

Code:

setx10
sety10
setx210
sery220
line
square

draws a line from (0,0) to (10,20) and a square with points on (0,0) and (10,20)

---------------------------------------------------------------

clear simply clears the canvas

---------------------------------------------------------------

wait: halts the program for a set amount of seconds

---------------------------------------------------------------

For/Next
Similar to the "repeat()" block, but with more complex syntax:

Code:

forx=2to25
pntx
next
print$done

Results in:

21
22
23
24
25
done

It is important to note that we don't yet support for loops inside of other for loops.

Last edited by MoreGamesNow (2012-02-25 19:31:15)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer