menu
Menu
Drakon.Tech logo
Drakon.Tech
Get started
Drakon.Tech documentationProgramming in DRAKONThe basics of programming with Drakon.TechAdvanced programming methodsGame examplesThe source codeLegacy tutorials (JavaScript 0.2)Tutorial 1. Hello world!Tutorial 2. Variables and functionsTutorial 3. Basic flow controlTutorial 4. ChoiceTutorial 5. For each loopTutorial 6. The arrow loopTutorial 7. SilhouetteTutorial 8. Lambdas and exceptionsTutorial 9. ModulesTutorial 10. Concurrent programming with scenariosExamplesLibraries

Tutorial 3. Basic flow control

The DRAKON equivalent of the if statement is the Question icon.

Let's create a program module and add a main function to it. We are going to make a function called printNumber. That function will take a number and output the text representation of the number. We start using printNumber as if it existed.

Calling functions in Drakon.Tech

Now, let's create the function. It will accept one argument called number.

We add a Question icon. If number is equal to 10, we print "ten." We also output number itself for reference. Let's build and run the project.

The question icon

We open the console and see online one line.

10 "ten"

Our printNumber function can handle only value 10. Let's add support for all other values. If number is not equal to 10, we print "some other value."

The question icon

We build and run again. Now, there are three lines in the output.

10 "ten"
20 "some other value"
30 "some other value"

Question icons can form complex decision trees. We will add another Question icon. If number is equal to 20, we print "twenty."

A more complex decision tree with the Question icon

We should get a greater variety of results now. We build, reload, and check the console.

10 "ten"
20 "twenty"
30 "some other value"

Note that it is possible to swap the "Yes" and "No" labels on a Question icon. Right-click it and choose "Swap Yes and No." To preserve the logic of the algorithm, we must rearrange the paths on the flowchart. I extensively use Copy, Cut, and Paste operations to achieve this. I also have to rewire some of the lines. First, I click on a line (or its end). Then, I choose the destination by clicking on the desired yellow circle.

A more complex decision tree with the Question icon

Let's build and run the project after this re-arrangement. As we expect, the core of the algorithm remained the same.

10 "ten"
20 "twenty"
30 "some other value"
close
Close
Drakon.Tech logo
Drakon.Tech home
Programming in DRAKONThe basics of programming with Drakon.TechAdvanced programming methodsThe source codeLegacy tutorials (JavaScript 0.2)