All Types of Custom Variables in Sketchware Pro
In Sketchware Pro (and Java for Android), a custom variable is a piece of memory that stores data.
You can use variables to store numbers, text, lists, or even Android objects.
The visibility and accessibility of a variable depend on its modifier — for example, public or private.
🔹 Access Modifiers Overview
| Modifier | Who Can Access | Common Use |
|---|---|---|
public | Any other class | Shared/global data |
private | Only inside this class | Internal variables (recommended default) |
protected | This class + subclasses | Used when extending classes |
| (none) | Classes in the same package | Rarely used in Android |
static | Shared across all instances | Global constants or counters |
🔹 Basic Data Type Variables
private int count = 0; // Whole numbers
private float price = 0.0f; // Decimal numbers
private double total = 0.0; // High precision decimals
private boolean isActive = false; // True or false
private char grade = 'A'; // Single character
🔹 String and Object Variables
private String username = "Guest"; // Text value
private File rootFolder = Environment.getExternalStorageDirectory(); // File path
private ArrayList<String> userList = new ArrayList<>(); // List of items
private HashMap<String, Object> userData = new HashMap<>(); // Key-value pairs
🔹 Android-Specific Types
private MediaPlayer player = new MediaPlayer(); // For playing audio
private Intent intent = new Intent(); // Used to start new activities
private Handler handler = new Handler(); // For running tasks later
private WebView webview1; // For displaying web pages
private Toast toast; // For showing messages
🔹 Public, Protected, and Static Examples
public String BOT_TOKEN = ""; // Accessible from anywhere
protected MediaPlayer bgPlayer; // Accessible in subclasses
public static int totalUsers = 0; // Shared across all instances
public static final String APP_VERSION = "1.0.0"; // Constant value
🔹 Combined Example: Mixed Variable Types
public class MainActivity extends Activity {
// Private variables (safe, local)
private int uploadCount = 0;
private boolean isUploading = false;
private String caption = "Auto Upload";
private ArrayList<String> imagePaths = new ArrayList<>();
// Public variables (accessible anywhere)
public String CHAT_ID = "";
public File rootFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
// Protected variable (accessible in subclasses)
protected MediaPlayer player = new MediaPlayer();
// Static variables (global/shared)
public static int totalUploads = 0;
public static String APP_VERSION = "1.0.0";
// Android objects
private Handler handler = new Handler();
private JSONObject configData = null;
}
🔹 Required Imports (if you use these types)
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONObject;
import android.os.Environment;
import android.os.Handler;
import android.media.MediaPlayer;
Tip:
In Sketchware, when you drag components (like
Button, WebView, or MediaPlayer) into your project,
Sketchware automatically generates their corresponding custom variables for you.
You only need to manually add extra custom variables for your own logic or data handling.
✅ Quick Reference Table
| Modifier | Type | Example | Use Case |
|---|---|---|---|
| private | int | uploadCount = 0; | Local number tracking |
| private | boolean | isUploading = false; | True/false state |
| public | String | BOT_TOKEN = ""; | Telegram bot token |
| protected | MediaPlayer | player = new MediaPlayer(); | Subclass audio player |
| public static | int | totalUploads = 0; | Global counter |
| private | ArrayList<String> | imagePaths = new ArrayList<>(); | Dynamic list |