Sketchware Custom Variables – Complete Guide
In Sketchware Pro (and Android Java), variables are used to store data that your app can use later. You can make them public, private, protected, static, or final — each one behaves differently. This guide explains each modifier with examples and best practices.
1️⃣ Public Variables
Public variables can be accessed from anywhere in your app — from other activities or classes. They are useful for global data, configuration values, or shared objects.
public String BOT_TOKEN = "";
public int uploadCount = 0;
public boolean isLoggedIn = false;
public when you need global access.🚫 Don’t use it for private or sensitive data.
2️⃣ Private Variables
Private variables can only be used inside the same class. This keeps your code secure and prevents unwanted access.
private String password = "1234";
private int clickCount = 0;
3️⃣ Protected Variables
Protected variables can be accessed by the class itself and its subclasses. It’s used in inheritance scenarios.
protected String userType = "Admin";
4️⃣ Static Variables
Static means the variable belongs to the class, not the object. It keeps the same value for all instances of the class.
public static String APP_VERSION = "1.0.0";
public static int totalUsers = 0;
static for constants or counters that must stay the same across the app.
5️⃣ Final Variables
A final variable can only be assigned once. Once you set its value, it cannot be changed — perfect for constants.
public static final String APP_NAME = "My Sketchware App";
📊 Comparison Table
| Modifier | Accessible From | Can Change? | Use Case |
|---|---|---|---|
| public | Everywhere | ✅ Yes | Global settings, shared data |
| private | Same class only | ✅ Yes | Local data, security |
| protected | Same class & subclasses | ✅ Yes | Inheritance and extensions |
| static | Class level (shared) | ✅ Yes | Global constants, counters |
| final | Any scope | ❌ No | Unchangeable constants |
🧩 Example: Using All Variable Types Together
public class MainActivity extends Activity {
public String username = "Guest"; // Accessible everywhere
private String password = "1234"; // Only inside MainActivity
protected String role = "User"; // Accessible by subclasses
public static int totalUsers = 0; // Shared counter
public static final String APP_NAME = "Sketchware Guide"; // Constant value
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
totalUsers++;
Toast.makeText(this, "Welcome " + username, Toast.LENGTH_SHORT).show();
}
}
📚 Quick Tips
- Use private for most variables inside a class.
- Use public static for global constants.
- Use final to prevent accidental modification.
- Keep names descriptive and clear (e.g.
uploadCount, notuc).
🏁 Conclusion
Understanding variable types helps you write cleaner, safer, and more efficient Sketchware code. Whether you need global constants or secure local data, choosing the right modifier makes all the difference.
Written by osunhive – Sketchware Pro Developer Blog