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

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.

Happy Birthday Memes: Laugh Your Way to Someone's Heart

Happy Birthday Memes: Laugh Your Way to Someone's Heart Introduction Birthdays are a special occasion to celebrate another year of life, and what better way to do it than with a good laugh? That's where happy birthday memes come in! These hilarious images are the perfect way to put a smile on someone's face and let them know you're thinking of them on their special day. Why Memes Are the Best Birthday Greetings * Relatable:  Memes often tap into universal experiences and emotions, making them instantly relatable to a wide audience. * Quick and Easy:  Sharing a meme is a hassle-free way to send birthday wishes, perfect for those last-minute greetings. * Memorable:  A funny meme is more likely to stick in someone's mind, making your birthday wishes unforgettable. * Versatile:  There's a meme for every type of person and occasion, from silly and goofy to heartfelt and sentimental. How to Use Happy Birthday Memes * Share on Social Media:  Spread ...

Cybersecurity Essentials: How To Stay Safe On The Internet

  Hi there, my name's Likhwa and welcome to Building Africa's Next Tech Unicorn. on this platform I give a behind the scenes look at what it takes to build a startup within the African context. In today's video, I'll be doing something different- I'll be talking about how you can stay safe online. This isn't meant to scare you or get you all paranoid, but to help you be more vigilant in protecting yourself and your loved ones from cyber threats.  Most people underestimate the dangers of the internet, but the more I am exposed to it, the more I wish I didn't need it. At times I wish I could just disconnect, get rid of all my devices and not have to worry about the constant threats that come with being online. I believe some of us are fortunate by default- especially those who live in countries like my Zimbabwe- because we hardly use credit cards to transact online and even when we do, its not like we have a lot of money- otherwise we would be a hacker's g...