×
Create a new article
Write your page title here:
We currently have 276 articles on Waste Of Space Wiki. Type your article name above or create one of the articles listed here!



    Waste Of Space Wiki

    Waste Of Space features a fully fleshed out programming system, allowing players to program Microcontrollers using a sandboxed subset of luau (which is itself a superset of lua) called Pilot.lua. Programming allows players to easily and efficiently implement complex logic and automation into their builds by writing code.


    This article serves as an introduction to programming in-game. It provides a handy yet detailed tutorial to get you started, a list of commonplace and useful programming-related parts to consider, some useful resources to help you with programming successfully, and at the end; a few inspiring examples. The talk page of this article hosts a community board to share useful and unique projects/code.

    Tutorial[edit | hide all | hide | edit source]

    Foreword[edit | hide | edit source]

    Microcontrollers are perhaps one of the most powerful tools waste of space provides you with. Knowing how to use them is paramount if you want to implement any kind of advanced automation or autonomy into your builds. This is not to say they are only for drones and factories, however. Programming expands your already large range of possibilities to a nearly boundless one.

    This tutorial will provide you with a brief guide on programming and coding in-game. Namely; programming and coding are not the same, though they are often confused as such. Coding is just writing instructions to the computer (code), while programming is the engineering of software. A programmer creates algorithms and solves problems, and then codes them to create a fully-fledged software solution.

    Please do not feel intimidated by this, as if it something out of reach to you. Though serious programming is not everyone's cup of tea, you do not need to be an AAA++ software engineer with 15 years of experience to code up your little idea. Everyone needs to start somewhere, and Waste of Space is hardly a source of difficult problems. Perhaps, if after reading this tutorial you find out that you like programming, you may even become one of those pros one day. Even in the worst case though, you will have learned an increasingly relevant skill and will have developed your logical thinking. If you haven't already gotten the gist, this guide is aimed at newcomers to programming.

    If you aren't sure whether or not to commit to learning programming, perhaps a well-known example (it's on the game's thumbnail!) of programming in waste of space can tip you over to either side.

    A video of the space arcade by iiMurpyh

    Learning to code[edit | hide | edit source]

    Getting started[edit | hide | edit source]

    While you may be tempted to start writing code right away you'll need to set up an environment for this first. This is what's called a development environment.

    As you'll just be writing some basic luau (a dialect of lua) throughout this tutorial, this will consist of just a text editor (and something to run your code with). A text editor can be as simple as just a notepad program so you have somewhere to jot down your code, or can be more complex and specialised for writing code. These types of text editors (code editors) often offer useful features such as automatic code completion and syntax highlighting (it colour-codes smaller bits of code, conveying their meaning or data type). A few suggestions for a code editor are listed below, complete with pros, cons, images, and links.

    • (the list)


    Once you've set up a text editor, there's one more thing to do before you can start coding: setting up a runtime environment. As lua is a scripting language - a programming language in which the instructions to the computer are stored as source code (the code as you wrote it, in textual format) - it must be translated to the computer in real time because computers can only understand binary (0s and 1s). This is what a runtime environment is for (in this case); it allows for the execution of scripts (source code) by translating them to machine code (instructions understandable to the computer) on the go.

    In this case, you'll need something that can run luau code. This guide recommends that you use Roblox Studio for these purposes. Using Studio to test your code isn't exactly the best, but studio is approachable for a beginner such as yourself. Besides, there aren't really any other options anyways. Later on, you'll switch from using Studio to testing code on Microcontrollers in-game.


    To set up Studio for testing your code, do the following:

    • Install Roblox Studio if necessary.
      • Go to https://create.roblox.com/
      • Click the 'Studio' button in the left side menu (under 'Quick links': at the bottom of the list). Alternatively, if you are not logged in, click the 'Start creating' button.
      • Click the 'Download' button
      • Install Studio by running the newly downloaded file
    • Open Roblox studio and under the 'New' tab click on the 'Baseplate' template
    • Open the file tab (Top left) and save this new experience (click 'Save to Roblox')
    • Close all of the windows except the 'Output' window (if present) and the 'Explorer' window.
      • If you don't have an output window, click the 'View' tab at the top of your screen and then click the 'Output' button to turn the window on
    • Resize the output window to be a bit bigger than by default if you have the screen space for it.
    • In the Explorer, hover over the 'ServerScriptService' and click the plus (+) icon beside it. Then, add a script to it (a regular script: make sure it's not a LocalScript or ModuleScript).


    If you've done everything correctly, you should now be in the built-in script editor. You should see the following:

    print("Hello world!")
    

    Go ahead and run this by clicking play at the top of your screen. You'll do this from now anytime you need to run your code. Unless you've chosen the built-in studio editor as your text editor of choice, you'll have to copy and paste the code you write into this script. Make sure to first select all of the text and only then paste your code so as to replace the existing contents.

    Once everything's loaded, you should see the following in the output window:

    Hello world!
    

    This means everything's working! You're now ready to start coding. If this isn't the case, double check you followed all of the instructions to the letter.

    What just ran is the print function - one of the simplest functions there is. You'll learn more about what a function is later, but for now know that it's basically a black box that does something with whatever you put between its parentheses - which are like the function's mouth into which you feed it values. In this case, the value you're feeding it is some text - a string (again, you'll learn more about these later; for now remember the name and that you create one by putting some text in between quotation marks, e.g. "text"). What the print function does is that it prints out (displays in the output) the text you gave it. In this case - Hello world!


    When you started reading your language for the first time, you needed to learn in what order to read the words before you. Code is read from left to right, line by line.

    The code before you currently only occupies a single line. Copy it, press enter, then paste it.

    You should now see the following two lines of code:

    print("Hello world!")
    print("Hello world!")
    


    Next, modify the code on the second line so it prints out Hi World!:

    print("Hello world!")
    print("Hi world!")
    

    Run this code. The output should be Hello World! and Hi World!; one after the other.

    This should give you a good idea of how code flows if you haven't already figured it out.

    You're now ready to move on onto the first real lesson: variables.

    Variables, scope[edit | hide | edit source]

    Say you want to store some information for future use; let's say that your friend later needs it so they can do something and you can't tell them it directly. Assume that you decide to write that information on a slip of paper.

    Now imagine that you also have an almost limitless number of really small boxes at your disposal. This is the computer's memory in this analogy.

    You can't just place your slip of paper anywhere as it'd get lost, so you decide to place your slip of paper into the nearest currently unused box.

    But how can your friend know which of those boxes to check for the slip of paper?

    The solution is to also label the box into which you place the slip of paper with a name specific to it: the entire box including its label is what's called a variable: a symbolic name (what you labeled the box with) associated with a storage location (the actual box itself).

    The information inside the box is the value of the variable. This value can be whatever, and can change with time.

    It's key to note that the box in this analogy is opaque. You can only know what's inside the box if you open it.


    Let's see how that translates into code; it turns out it's really simple.

    Delete any code you have in the script you're using to test your code, then add the following:

    local x = 3
    print(x) --prints out 3
    

    Let's break this down line by line:

    • local x = 3 defines some variable x to be equal to 3
      • x is the name of the variable
      • = assigns the value of the variable to be whatever is on the other side of it
      • 3 is the value you're assigning to the variable. In this case, it is a number.
    • print(x) prints the value of the variable
    • --prints out 3 is a comment - an annotation to source code. It's always at the end of a line and is created by using two dashes (-). It is ignored when running the code.


    Try playing around a bit with this code by changing the value of the variable: perhaps by changing it to another number, or perhaps to a string ("Hello world!", for example).

    You may notice that what local does wasn't defined. local sets the scope of a variable. Scope (or visibility) is a property of variables which defines where (that is in which scope blocks) their name binding is valid (so, if a is equal to 1, where a being equal to 1 is the case). Let's look at an example to make this clearer, and break it down line by line as before:

    local a = 3
    
    do
     print(a) --prints out 3
     local x = 4
     local a = 5
     print(x) -- 4
     print(a) -- 5
    end
    
    print(a) -- 3
    print(x) -- nil
    
    • local a = 3 sets a to be equal to 3, as you should know by now.
      • local sets the scope of the variable to local. This means that the variable's binding is only valid within its scope block or in scope blocks within it's scope block. Imagine scope blocks as the folders on your computer (but not quite). Say you have a home folder and a documents folder, both with some files inside of them. If you're in the home folder, you can only access the files inside of it. You'll only be able to see the files within the documents folder if you go into it. However, unlike with real folders, if you're in the documents folder in this case you'll also be able to see everything within the home folder. If scope still confuses you, just know that you should always define variables by using local (...) = (...)
        • The other option is setting the scope of a variable to global. To set a variable's scope to global, just don't use local before it. This is equivalent to defining a local variable at the top scope (local a = 3 in the above example). Local variables should be preferred whenever possible.
    • do .. end creates a new scope block. do starts it and end ends it.
    • print(a) prints out the value of a. As a already had its value assigned in a higher scope, a is (also) equal to 3 here.
    • local x = 4 ...
    • local a = 5 sets a to be equal to 5. This is NOT the same as assigning a a new value (a = 5). This overrides the other a with a new a; equal to 5: not 3, but only in its local scope.
    • print(x) prints out 4 as this is what x was defined as, at least in the current scope.
    • print(a) now prints out 5, as a was defined to be 5 in this scope.
    • print(a), now outside the scope block, prints out 3 because a is only equal to 5 within that one specific scope block. Outside of it, a refers to the original a and is equal to 3: what it is defined to be in the top scope block.
    • print(x) prints out nil. nil represents no value - not as in 0, but as in the complete absence of anything. x is equal to nil for the same reason why printing a before this gave 3: x is only defined to have a value within its scope block; as it wasn't defined in any way outside of it, it lacks one.


    Feel free to play around a little with what you've just learned. Learning by doing is the best way to learn. If anything's been left slightly unclear, try going over everything again once more; perhaps slower. Once you feel you're ready, please take the following quiz to check your comprehension:

    1 Which of the following defines a to be equal to the number 4; in the local scope?

    a = 4
    do a = 4 end
    local a = 4
    local a = "4"

    2 Defining variables in the local scope is always preferred

    TRUE
    FALSE

    3

    What will the following code print out?
    local hello = "Hello world!"
    print(hello)
    

    hello
    Hello world!
    "Hello world!"
    'hello'

    4

    Consider the following code:
    local b = 2
    local p = 3
    
    do
      b = 5
      print(p)
    end
    
    print(b)
    

    The code will print out:

    5, then 2
    2, then 3
    3, then 5
    3, then 2

    5

    Complete the missing lines:
    local c = 32
    local s = c
    
    do
      c = 54
      do
        ...
        ...
        ...
        print(s)
      end
    end
    

    If the output of the code was 32, then 54, then 24.

    First missing line:

    Second missing line:

    Third missing line:


    - types

    - numerical operators, numerical operators on variables

    - logical operators, scope

    - tables, dictionaries

    - loops - basic

    - strings - basic operations

    - more operators, operator shenanigans

    - functions (basic. just an introduction;)


    - tasks should be included for each of these. these tasks should be quizzed (use the quiz extension).

    Computational thinking[edit | hide | edit source]

    - problems, and how they are broken down into programmable steps. just a lot of problems. practice makes perfect

    - small project at the end

    Coding revisited[edit | hide | edit source]

    - strings 2

    - basic OOP

    - functions/methods 2 (stuff like recursion goes here)

    - more complex collections (stacks, queues, etc. - with implementation details/a preprogrammed script available for these)

    - built in functions (if possible in any way this should be introduced bit by bit through earlier sections)

    - coroutines

    - error handling


    - quizzes after every smaller chunk. more than for learning to code as this is tougher.

    The Microcontroller[edit | hide | edit source]

    - parts

    - built in microcontroller functions

    - JSON and modems; web requests

    - add a quick little quiz and small project at the end

    Programming at last[edit | hide | edit source]

    - everything put together and tested with practical projects

    - thorough explanations and solutions should be given for each project. throw in some software engineering stuff here as well.

    Afterword[edit | hide | edit source]

    - buh bye

    Parts[edit | hide | edit source]

    Resources[edit | hide | edit source]

    Examples[edit | hide | edit source]

    A flappy bird arcade machine, made by iiMurp
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.