×
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

    Programming/Staging: Difference between revisions

    Content added Content deleted
    m (smmall fixes)
    (added variables section (mind the alt; forgot to transfer my password manager's vault file again))
    Line 17: Line 17:


    === Learning to code ===
    === Learning to code ===

    ==== Getting started ====
    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'''.
    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 [https://luau-lang.org luau] (a dialect of the [https://lua.org/ 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 specialized 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.
    As you'll just be writing some basic [https://luau-lang.org luau] (a dialect of [https://lua.org/ 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)
    * (the list)
    Line 54: Line 56:
    Once everything's loaded, you should see the following in the output window:
    Once everything's loaded, you should see the following in the output window:
    Hello world!
    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.
    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 - this is like its 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). What the print function does is that it prints out (displays in the output) the text you gave it. In this case - Hello world!
    - Use this as an introduction to basic code flow



    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:<syntaxhighlight lang="lua">
    print("Hello world!")
    print("Hello world!")
    </syntaxhighlight>


    Next, modify the code on the second line so it prints out <code>Hi World!</code>:<syntaxhighlight lang="lua">
    print("Hello world!")
    print("Hi world!")
    </syntaxhighlight>Run this code. The output should be <code>Hello World!</code> and <code>Hi World!</code>; 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 ====

    Imagine you want to store some information for future use: say your friend needs it later so they can do something. Say you write that information on a slip of paper.

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

    You then 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:<syntaxhighlight lang="lua">
    local x = 3
    print(x)
    </syntaxhighlight>
    Let's break this down line by line:

    * <code>local x = 3</code> defines some variable x to be equal to 3
    ** <code>x</code> is the name of the variable
    ** <code>=</code> assigns the value of the variable to be whatever is on the other side of it
    ** <code>3</code> is the value you're assigning to the variable
    * <code>print(x)</code> prints the value of the variable


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


    You may notice that what <code>local</code> does wasn't defined.
    - variables, global vs local


    - types
    - types
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.

    Recent changes

  • Axenori • 3 days ago
  • Voivsone • 4 days ago
  • Axenori • 4 days ago
  • Axenori • 5 days ago
  • Cookies help us deliver our services. By using our services, you agree to our use of cookies.