The Nim Game – MIT App Inventor Tutorials

Nim is a mathematical strategy game which two players take turn to remove any number from different piles. There are many variations of the game, in this tutorial, there will be three piles with number three, four and five respectively. The winner is the player who takes the last number.

UI Components:
Label, Horizontal Arrangement, Button, Notifier


Start Game

Create three variables to keep track of the number in different piles and also a variable to keep track the player’s turn. This below example, updateButton procedure is created to update the text of all three buttons when any of the number changes. When RestartGameButton is clicked, reset the variables and UI.

Button Click

When user clicked any of the three buttons, we will use Notifier text dialog to ask for the number user will be taking away from the selected button. After user input a number, we will need to check for several invalid input conditions:

  1. Input number should be less than remaining number on the button
  2. input number should not be less than zero

If input is valid, we will then check for the winning condition. If the sum of all three piles is zero, then the player wins the game.

Above example shows only the logic for Button1, the same logic needs to be done for Button2 and Button3. If the winning condition is not met, update the isPlayerOne variable. We will also change the UI to indicate different player’s turn.

Complete Program

MIT App Inventor Generate QR Code Offline

This app will generate a QR code using string input by user. The QRCodeCreator extension was used for the QR generation. Add BarcodeScanner and File components to provide required dependency and permission for the app to function correctly.

Complete Program

Common Error

Failed resolution of: Lcom/google/zxing/ EncodeHintType

This error is caused by missing dependency. Solve this problem by adding the BarcodeScanner  component into your application

Error 908: The permission Write_External_Storage has been denied

Your application needs to ask for WRITE_EXTERNAL_STORAGE permission during initialization or runtime.

Permission name: android.permission.WRITE_EXTERNAL_STORAGE

If the access is denied even after permission is granted. Add the file component to allow storing and retrieving of files on your device.

Learn Kodular, Thunkable & App Inventor – Start with Programming Basics


The rise of low-code/no-code platforms allow anyone to easily create mobile apps. In the low-code/no-code mobile apps development space, three notable platforms are MIT App Inventor, Thunkable, and Kodular. Both Thunkable and Kodular originated from MIT App Inventor, hence they all have similar interfaces and mechanics on the app building process. MIT App Inventor is maintained by Massachusetts Institute of Technology for educational purposes while the latter two aimed to help users create commercial applications.

All three platforms use Google’s Blockly visual programming language as their foundation for app development. Even though no code needs to be “written” and the complex programming syntax is abstracted away with Blockly, users ought to understand the fundamental concepts of programming in order to achieve different results effectively. Here are some of the fundamental concepts in programming that will help you in your app building process:

  1. Variables & Data Types
  2. Operators
  3. Conditional
  4. Iteration / Loops
  5. Function / Procedure

You learn these programming concepts with our interactive Blockly programming platform.

Variables & Data Types

In computer programming, a variable or scalar is a storage location (identified by a memory address) paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value.

– Wikipedia

You can think of variables as containers used to store information during a program execution. We can retrieve the information and reuse them throughout our program. Different programming languages have different ways of creating variables inside a program. In programming languages such as C, C++, and Java, data type of the variable need to be specified during creation and you will only be able to store the specified data into the variable. However, in Blockly we do not need to specify the data type and variable can be used to store any type of value. This is similar to programming languages such as JavaScript, Python, and PHP. Some of the basic data types in Blockly:

Primitive Data Type

  • String
  • Number
  • Boolean
  • null / undefined (special data types)

Composite Data Type

  • Object / Dictionary
  • Array / List
  • Function / Procedure (Not assignable in Blockly)

Examples of creating variables with different data types in Kodular.


Operators are used to perform mathematical, relational or logical operation. We can combine more than one math operator to perform a more complex calculation. Computation of result follows convention math precedence that is:

  1. Parentheses
  2. Exponents
  3. Multiplication and Division
  4. Addition and Subtraction

Mathematic Operators

Relational Operators

A relational operator is used to create conditional expression which will return a Boolean – either true or false. Using it with if statements, we will be able to create algorithms where program can make decision to execute different code based on the given conditional expression.


In programming, conditional statements are used to decide different computations at run time. There are several types of conditional statements:

  • if statement
  • if…else statement
  • if…else if…else statement
  • switch statement (not available in Blockly)

The if statement checks whether a given conditional expression evaluates to true, if so, the statement will be executed.

If the conditional expression of an if statement evaluates to false, then the else statement will be executed.

The else if statement adds another condition to check when the first if statement is false.

Iteration / Loops

In programming is used to repeat a block of code until a specific condition is met. There are two main types of loop:

  • for loop
  • while loop

A for loop requires an initialization statement to declare a loop control variable, a test statement to test against the variable and an increment statement to update the variable. The test statement will be evaluated after every loop and if it is true, the process repeat itself. In the example below, the code blocks in the for loop will be executed for 5 times.

A while loop allows code to be executed repeatedly until a given conditional expression is evaluated as false.

Function / Procedure

Even a simple computer program contains hundreds if not thousands of lines of code. Most of the time, part of these codes is repeated. Instead of typing out the same instructions over and over, we can group them into chunks called function or procedure. Value can also be passed into a function as variables, they are also known as parameters.

Function can have return values – the values that a function returns when it has completed.


In order to develop any logic in your mobile app using either Kodular, Thunkable or MIT App Inventor, understanding the basic concepts of programming give you the ability to achieve it effectively. Diving in without the fundamentals is like solving complex equations without know basic algebra. Our interactive block-based coding platform is designed to help students learn the fundamentals so that they have the skill to build more advance application.

Number Memory Game – MIT App Inventor Tutorial


In this app, numbers will appear in a 4×4 grid for a certain amount of time. User needs to remember all the numbers and tap on the buttons according to number sequence from 1 to 16.

UI Components:
Label, Horizontal Arrangement, Button (lots of button 😱), Horizontal Arrangement, Clock, Notifier

Clock – Enabled (false), TimeInterval (5000)


Generate Random Number Sequence

First, generate a list with incremental numbers from 1 to 16. Then, apply Fisher-Yates algorithm to shuffle the list to have random permutation.

Show Numbers when Game Start

When the start game button is clicked, generate the random number list and show the numbers on all 16 buttons from left to right.

Enable the clock when game start to start the timer. In this example, the time interval was set to 5000ms and once the Clock.Timer event called, disable the timer and hide all the text on buttons.

Finally, we need a variable to keep track of the button clicks and the number will be displayed using the top label.

Game Play

For each button click, increase the clickCount variable by one and check if the number on the button matches the number in our generated array based on its sequence. In below example, checkClick function will take in an argument which will be used as index to get the value in the generated list.

Complete Program