Intro to Functions (PlayBASIC Tutorial)
In this tutorial, we take the next step beyond classic BASIC flow control and move into structured programming with functions.
We kick things off with a quick refresher on Gosub / Return and how subroutines alter program flow by jumping out to a labeled block of code and then returning to the caller. From there, we break down how this mechanism works under the hood (including the stack and return points), along with some of the common pitfalls—like missing return statements and unpredictable program behaviour in larger projects.
From that foundation, we transition into functions a more modern and structured way to organize your code.
You’ll learn:
* How to convert a simple subroutine into a function
* Why functions are safer and more predictable (compiler checks, defined entry/exit points)
* How to call functions just like built-in commands
* The concept of variable scope (and why your loop counter suddenly stops working!)
* The difference between local and global variables—and why globals aren’t always the best solution
* How to pass data into functions using parameters
We then build on this by creating practical examples:
* A custom distance calculation function (with return values)
* A simple string processing function (trimming and replacing characters)
* Handling different data types (integers, floats, and strings)
By the end of the video, you’ll understand how functions let you break large, messy programs into smaller, reusable, and more manageable pieces—essentially creating your own custom commands inside PlayBASIC.
In this tutorial, we take the next step beyond classic BASIC flow control and move into structured programming with functions.
We kick things off with a quick refresher on Gosub / Return and how subroutines alter program flow by jumping out to a labeled block of code and then returning to the caller. From there, we break down how this mechanism works under the hood (including the stack and return points), along with some of the common pitfalls—like missing return statements and unpredictable program behaviour in larger projects.
From that foundation, we transition into functions a more modern and structured way to organize your code.
You’ll learn:
* How to convert a simple subroutine into a function
* Why functions are safer and more predictable (compiler checks, defined entry/exit points)
* How to call functions just like built-in commands
* The concept of variable scope (and why your loop counter suddenly stops working!)
* The difference between local and global variables—and why globals aren’t always the best solution
* How to pass data into functions using parameters
We then build on this by creating practical examples:
* A custom distance calculation function (with return values)
* A simple string processing function (trimming and replacing characters)
* Handling different data types (integers, floats, and strings)
By the end of the video, you’ll understand how functions let you break large, messy programs into smaller, reusable, and more manageable pieces—essentially creating your own custom commands inside PlayBASIC.