Skip to main content

Understanding the Sketchware blocks- Variables


Sketchware blocks


We had covered some ground and some are still unsure about what the blocks do and mean. So in the next few days we will be looking at some of these and what they do. We will start with the Orange blocks at the top. These are variable blocks.

TYPES OF VARIABLES

Think of variables as place holders and these variables can be used to temporarily hold numerous values. There are four types of variables:
1. Boolean
2. Number Variable
3. String variable
4. Map variable

We'll cover Boolean Variables later. Today we'll cover Number, string and map variables.

BOOLEAN VARIABLES

Sketchware boolean variable


A boolean is a data type that has only two possible values. For example a user's  can be logged in or logged out. So the value of that boolean can only either be true or false. In the image above I have created a boolean variable called isRunning. I can use this  to determine when the app is running by setting the value to true when the app starts(onStart). then I can also specify what happens when the app is running. 

NUMBER VARIABLES

Sketchware number variable


A Number variable only holds numerical values and is useful for performing calculations. Number variables can be easily identified using their oval shape. Remember back in high school when you were doing equations and were given something like x + y = z? Well, think of a variable as a placeholder similar to x in that equation. For example, if we are creating an app that adds 2 numbers, we need to allow the app the flexibility to function the same regardless what the user types into the field. So instead of calculating using a fixed number like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 we replace the numbers with a variable whose value can change. We can give this variable the name x. That way even if x changes, the result still proves true and meets any set rules. 

So in our app, instead of saying _2 + 4 = 6_ we would convert whatever text we receive in our edittext to a variable. We can give these variables simple names like:

a, b, c 
num1, num2, num3
day1sales, day2sales, day3sales

This will make it easier to make calculations. So it will then look like this in our logic:

a + b = c
num1 + num2 = total
day1sales + day2sales = salestotal

When you add a number variable in Sketchware, in addition to the variable, 3 new blocks are added. These are 

Set Number to- this sets the value of that specific variable to whatever number is placed in the blank oval. This can be another variable, a calculation or any number. PLEASE NOTE THAT THIS BLOCK DOES NOT DISPLAY A NUMBER. TO DISPLAY A NUMBER YOU WILL STILL NEED TO SET TEXTVIEW TO THE VALUE OF THAT VARIABLE.

Increase number by 1- as the name states, this block increases the number variable

Decrease number by 1- this block decreases your number variable by 1


STRING VARIABLES

Sketchware string variable

Variables can also be used to replace alphanumeric text. String variables are rectangular in shape. This can be used in instances whereby the user enters lots of temporary data but each with different values. For example in a camera app, you can use string variables to store image names. Instead of you creating a list of individual names, you can use a string variable to collect time and location whenever a picture is taken and use these as the image name.

MAP VARIABLES
Sketchware map variable

These are used to store data which contains multiple fields of data at each key. If you are creating a chat app, you will want to collect *date, time, message, user ID.* so instead of recording these and storing them in a list of textviews at each point a message is sent, you can store it temporarily in a map variable.

Comments

Popular posts from this blog

Hip hop and RnB songs to apologize to your partner

Love is a beautiful thing, but it often goes wrong. This often leads to pain, suffering and sorrow.  Being imperfect beings, hearts tend to get broken all the time regardless how hard we may try to avoid it.  The heartbreak is often inadvertent but at times we find ourselves in the wrong. An oversight, a word unsaid or even a lapse in our judgement can cause our loved ones harm. This doesn't always have to be the end though. Oftentimes, relationships can be mended by simply uttering three simple words: "I AM SORRY". This article is a collection of some of my favourite 'I'm sorry' songs. I hope you'll enjoy these apology songs, but more importantly, I hope you will get a few quotables and some wisdom nuggets from them.  The best apology however, is to change behaviour (got that from a Jay Z interview) so as you apologize, please remember that it was your actions that hurt them. The best apology is one which involves you not repeating those same mistakes aga

Php date: How to get the first and last day of the week

In this tutorial, I'll show you how to get the first and last day of the week in php. By default, in PHP the week runs from Monday to Sunday. However we'll cover two methods to get the first and last day for both those who consider Sunday or Monday as their first day of the week. We will be using 2 functions to achieve this: date() strtotime() We will use a combination of these two functions and store the result in a variable.  How to get the first day of the week If you want to get Sunday, use this method: $firstday = date('l Y-m-d', strtotime("sunday -1 week")); echo $firstday; If you want to get the date for Monday, this current week, use this method: $monday = date('l Y-m-d', strtotime("monday -1 week ")); echo $monday; How to get the last day of the week The following code will give you Saturday as the last day of the current week. $lastday = date('l Y-m-d', strtotime("saturday 0 week")); echo $last

How to easily create background notifications in Sketchware(original)

How to easily create background notifications in Sketchware(original) One of the keys to building a successful app is to find mechanisms that will keep your users engaged. You can do this by using background notifications. This tutorial will show you how to do that in Sketchware. We will cover: 1. How to create notifications in Sketchware 2. How to show these notifications even when the app is closed.