slack-basic

Basic app for slack

View on GitHub

Slack Basic Tutorials

Reading and Writing

As in normal basic, you use the PRINT and INPUT commands to interact with the user. Let’s build a simple calculator.

10 INPUT "Enter the first number"; N1
20 INPUT "Enter the operator (+, -, /, *)"; OP$
30 INPUT "Enter the second number"; N2
40 IF OP$ = "+" THEN RESULT = N1 + N2
50 IF OP$ = "-" THEN RESULT = N1 - N2
60 IF OP$ = "*" THEN RESULT = N1 * N2
70 IF OP$ = "/" THEN RESULT = N1 / N2

Notice that we don’t have cool stuff like else and if/else statements, so if you need to do something more complicated, you have to structure things a bit differently.

80 PRINT "The result is "; RESULT

PRINT will print everything you pass to it. You can use a comma delimiter, a semicolon, or just a space! These are all equivalent:

Slack Basic will buffer print statements for a second before it sends them to the client. This saves on calls to the slack API but also means that you can’t call PRINT a million times to spam the channel. Additionally, you are not allowed to call PRINT more than 25 times within a few seconds. Usually this means you are up to something nefarious.

Graphics

Primitive graphics are supported in the hopes that someone will make something truly useless but amazing. To start using graphics, you need to use the GRAPHICS statement.

GRAPHICS 512, 512

This will create a “graphics canvas” of 512 by 512 pixels. You can now use graphics statements to draw to this canvas. Let’s draw a couple of boxes.

10 DATA "#ff0000ff" "#00ff00ff" "#0000ffff"
20 DIM COLORS$(2) : READ COLORS$(0), COLORS$(1), COLORS$(2)
30 DEF FN COLOR() = COLORS$(INT(RND() * 3))
40 DEF FN NUM(MAX) = INT(RND() * MAX)

Woah! What’s going on here.

50 FOR I% = 0 TO 2
60   C$ = FN COLOR()
70   X = FN BETWEEN(0, 512)  
80   Y = FN BETWEEN(0, 512)
90   S = 25 + FN NUM(25)
100  BOX C$, X, Y, S, S
110 NEXT

This is a mouthfull.

RUN this and you should get something that looks like this.