×
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: Difference between revisions

    Content added Content deleted
    m (Made article discoverable by search engines, added an fyi editorial comment)
    (Added a TON of more info, including more parts and tutorials. Fix any errors please)
    Line 1: Line 1:
    [[File:ComputerDiagram.png|alt=|thumb|300x300px|Diagram for how to construct a basic computer including a MicroController.]]The game features an in-depth programming language that allows you to write and execute software that can manage and manipulate the state of other objects in-game. The name of this programming language is called '''Pilot.lua''', which is a reference to rbx.lua.
    [[File:ComputerDiagram.png|alt=|thumb|300x300px|Diagram for how to construct a basic computer including a MicroController.]]The game features an in-depth programming language that allows you to write and execute software that can manage and manipulate the state of other objects in-game. The name of this programming language is called '''Pilot.lua''', which is a reference to rbx.lua. It is recommended to learn rbx.lua before you learn pilot.lua. Coding in this game is super helpful, as it allows for much more possibilities and stuff you can do.
    The main parts of programming are
    The main parts of programming are:

    *[[Microcontroller]] - An object that stores and runs code when triggered by polysilicon and powered.
    *[[Port]] - Allows the microcontroller to interact with other objects, trigger and configure, etc.
    *[[Screen]] - A programmable object that can display user interface objects such as TextLabel, ImageLabel, etc.
    *[[Disk]] - Stores values in a directory-like format.
    *[[EthernetCable]] (Optional) - Allows to connect to Objects from [[Port|Ports]], this object is highly recommended. <!-- FYI This is a thing people often get wrong when referring to networking equipment. Ethernet is actually just the protocol which most networks today use for transferring data. The actual cable is often, but not necessarily, some of the cat(n) cables (CAT6 being the most popular one as of 24 Jun 2023). The male end of the connector is, with cat6, the 8p8c modular plug. Note that other CAT(n) cables often use different plugs. As for the "Port", in the case of an 8p8c plug it is most often the RJ45 (Registered jack 45). -->


    *[[Microcontroller]] - An object that stores and runs code when triggered by polysilicon and powered. This is the core component of coding, as its the only way to run code in this game.
    *[[Port]] - Allows the microcontroller to interact with other objects, trigger and configure, etc. This is also a very important part, because it is the ONLY way to allow microcontrollers to interact with the outside world.
    *[[Screen]] - A programmable object that can display user interface objects and UIs such as TextLabel, ImageLabel, etc. This is very important for creating custom UIs and displaying text. However, if you are new to coding and don't understand UIs too much, then it is recommended to just use [[Sign|signs]].
    *[[Disk]] - Stores values in a [https://create.roblox.com/docs/education/coding-5/intro-to-dictionaries dictionary] format. It is very useful to store large amounts of info like code and [[Model Builder|model codes]]. It is also very useful, as microcontrollers don't carry information across turning on and off, while disks do.
    *[[EthernetCable]] (Optional) - Allows you to extend the range of [[Port|ports]], not required to get parts from a [[Port]], although highly recommended if your creation is large, and you need get parts far away from the [[Port]]. Note: The [[EthernetCable]] needs to be touching the hole on the [[Port]] in order to work.<!-- FYI This is a thing people often get wrong when referring to networking equipment. Ethernet is actually just the protocol which most networks today use for transferring data. The actual cable is often, but not necessarily, some of the cat(n) cables (CAT6 being the most popular one as of 24 Jun 2023). The male end of the connector is, with cat6, the 8p8c modular plug. Note that other CAT(n) cables often use different plugs. As for the "Port", in the case of an 8p8c plug it is most often the RJ45 (Registered jack 45). -->
    *(UNSTABLE) [[Router]] (optional) - The router is the [[Antenna]] of [[EthernetCable|ethernet cables]]. It does the same thing as [[EthernetCable|ethernet cables]], only wireless. This is incredibly useful, as it allows for wireless connections, and allows for parts to be connected from across the region. Note that this is ONLY in [https://www.roblox.com/games/4569607361/Waste-Of-Space-UNSTABLE unstable].


    Other less-important items in coding include:
    *[[Modem]] - Extremely useful for creating makeshift internets of sorts. It allows messages to travel across the entire universe! <!-- PLEASE add info on postrequests and stuff, bc I don't understand them -->
    *[[LifeSensor]] - Very useful for making smart turrets and other stuff. It is used to return names of players and their Vector3 location.
    *[[Gyro]] - while the [[Gyro]] is not a coding exclusive part like most, it has a programmable method called gyro:PointAt(vector3 position). This, along with [[LifeSensor]], can make an accurate turret, or if you just want to make the gyro point at a certain place.
    *[[Keyboard]] - extremely useful for inputting text, commands, or when attached to a [[Seat]] or [[VehicleSeat]], can be used to get keys pressed to make keybinds.
    *[[Microphone]] - extremely useful for making chat commands or chat logs of some sort, because its used to get anything said in chat.
    *[[Instrument]] - Very useful for giving information to a microcontroller, such as outside temp and position.
    *[[TouchScreen]] - A improved version of the [[Screen]], as it allows you to get the X and Y (in offset) of the cursor on the screen.
    The code below is code for a smart turret that takes chat commands and targets players accordingly, with the command "target playername"<syntaxhighlight lang="lua" line="1">
    The code below is code for a smart turret that takes chat commands and targets players accordingly, with the command "target playername"<syntaxhighlight lang="lua" line="1">
    local Gyro = GetPartFromPort(1, "Gyro") -- Gets gyro attached to port 1
    local Gyro = GetPartFromPort(1, "Gyro") -- Gets gyro attached to port 1
    Line 29: Line 37:
    There are many functions in Pilot.lua that allow you to interact with other objects. These are the following default functions listed.
    There are many functions in Pilot.lua that allow you to interact with other objects. These are the following default functions listed.


    *GetPort(ID) - Returns a port instance that can be used in other functions.
    *GetPort(ID) - Returns a port instance that can be used in other functions. It is only really recommended if your going to do something like port:Connect("Triggered")
    *GetPartFromPort(ID or Port Instance, ClassName) Returns a part if found directly attached to a port. An example would be GetPartFromPort(2, "Screen")
    *GetPartFromPort(ID or Port Instance, ClassName) Returns a part if found directly attached to a port. An example would be GetPartFromPort(2, "Screen")
    *TriggerPort(ID or Port Instance)
    *TriggerPort(ID or Port Instance) - pretty self explanatory, sends a [[Button|trigger signal]] from the given port or port instance
    *GetPartsFromPort(ID or Port Instance, ClassName) Returns multiple parts if found directly attached to a port. Must have "'''for i = number, number'''" command in Microcontroller to function.
    *GetPartsFromPort(ID or Port Instance, ClassName) Returns an [https://create.roblox.com/docs/luau/tables array] of different parts attached to the [[Port]]. In order to use, it is recommended to use [https://create.roblox.com/docs/education/coding-5/pairs-and-ipairs ipairs], however, a "'''for i = number, number do'''" along with a "'''Parts[i]'''" will work too.


    All objects will contain certain programmable properties and functions. However, all instances will contain the following properties:

    *Configurable properties, for example an ionrocket's thrust speed property
    *ClassName, which is simply the name of the object
    *Object:Trigger(), which simply triggers the object
    *Object:Configure({Property=NewValue}), which configures the part to the given dictionary/table
    *Object:Connect, which is similar to roblox connections (part.Touched:Connect). An example includes TouchTrigger:Connect("Touched", function() end)


    All objects will contain certain programmable properties and functions. However, all instances will contain the following properties and methods:
    *Properties
    **Configurable properties, for example an ionrocket's thrust speed property
    **ClassName, which is simply the name of the object
    *Methods
    **Object:Trigger(), which simply triggers the object
    **Object:Configure({Property=NewValue}), which configures the part to the given dictionary/table
    **Object:Connect, which is similar to roblox connections (part.Touched:Connect). An example includes
    TouchTrigger:Connect("Touched", function() end)
    *Events
    **part:Connect("Triggered", function() end)
    Certain parts however will have their own special properties.
    Certain parts however will have their own special properties.

    *Screen
    *Screen
    **Methods
    **Screen:CreateElement(GUIClassName, Properties), an example includes Screen:CreateElement("TextLabel", {Text = "Hello World!"; TextScaled = true});
    ***Screen:CreateElement(string GUIClassName, dictionary Properties), an example includes Screen:CreateElement("TextLabel", {Text = "Hello World!"; TextScaled = true});
    **Screen:ClearElements(), which clears all elements in a gui
    ***Screen:ClearElements(), which clears all elements in a gui

    *Disk
    **Methods
    ***disk:Write(string Key, any Value) writes a value in the disk with the given key.
    ***disk:Read(string Key) Reads the value in the disk with the given key. If there is no value, returns nil.
    ***disk:ClearDisk() clears the disk
    ***disk:ReadEntireDisk() returns a dictionary of all the values and keys in a disk.

    *Keyboard
    **Events
    ***keyboard:Connect("KeyPressed", function(keycode key, string key, string player) end) fires when someone presses a key while sitting on a [[Seat]] attached to the keyboard
    ***keyboard:Connect("TextInputted", function(string Text, string player) end) fires when someone presses on the [[Keyboard]] to open the text menu, and submits text. Note: the keyboard adds an extra character at the end on accident, because you press enter to submit, and so it adds an extra character.

    ==Small Tutorials==
    These tutorials are assuming you know a thing or two about coding already. More are yet to come.
    ===Screen===
    The [[Screen]] is a confusing part for beginner programmers, because of all the confusing stuff like UDim2. So, here's an explanation. [[Screen|Screens]] are a very useful item for displaying information, allowing for much more possibilities then just simply configuring [[Sign|signs]]. While [[Sign|signs]] will work for displaying text, it doesn't have nearly as much possibility as [[Screen|screens]]. [[Screen|Screens]] can display multiple elements, and have custom size/position. However, when it comes to creating [[Screen]] elements, it can be confusing because it uses a whole new data type called [https://create.roblox.com/docs/reference/engine/datatypes/UDim2 UDim2]. UDim2 is a data type consisting of 4 values. The order goes XScale, XOffset, YScale YOffset,. ''What the heck does all that mean??'' Well, simply put, Offset is the X or Y size/position of the element in pixels. Scale is the X or Y size/position in screen sizes. ''What do you mean, "screen sizes"???'' 1 scale is equal to the entire size of the screen. 1 XScale is equal to the width of the screen, while 1 YScale is equal to the height of the screen. Scale is very important, as it allows for the ScreenElement to look the same no matter the size of it. In order to make a screen element cover the entire screen, you would put the scale at 1 for both. So what you can do is make the screen size equal to UDim2.new(1, 0, 1, 0). ''Whats the point of putting the zeros? Is there an easier way to do it?'' There is an easier way to do it. instead of using UDim2.new, you can use UDim2.fromScale, which is where you only need to put 2 values instead of 4, UDim2.fromScale(1, 1). Before I continue, if you need further help understanding UDim2, go visit the [https://create.roblox.com/docs/reference/engine/datatypes/UDim2 Creator documentation page]. Now comes the part where I actually explain how to make a new element. So first to create the element, you need to get the screen from the port. <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    </syntaxhighlight>
    Next we would need to clear any elements that are already on the screen using screen:ClearElements().
    <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    </syntaxhighlight>
    Now, to create the element using screen:CreateElement().
    <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("classname", {properties}) -- creates an element with the given name and properties
    </syntaxhighlight>
    Now, we must add the Classname of element we want to create. I will use TextLabel.
    <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", {}) -- creates an element with the given name and properties
    </syntaxhighlight>
    Now, we need to add a few properties.
    <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", { -- creates an element with the given name and properties
    Text = "Hi!", --Sets the text to Hi!
    TextScaled = true -- Automatically scales the text to fit the screen
    })
    </syntaxhighlight>
    Now, lets use what we learned above, and use UDim2.fromScale to make the size and position.
    <syntaxhighlight lang="lua" line="1">
    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", { -- creates an element with the given name and properties
    Text = "Hi!", --Sets the text to Hi!
    TextScaled = true, -- Automatically scales the text to fit the screen
    Size = UDim2.fromScale(1, 1), --Makes the size cover the whole screen
    Position = UDim2.fromScale(0, 0) --sets the position
    })
    </syntaxhighlight>
    Congrats! You made your first [[Screen]] element. A few more notes are:
    *Position is the position of the element in the top left corner
    *when doing scale for position, the top is y=0, the bottom is y=1, the left is x=0, the right is x=1. This confuses some people because positive y is actually down, not up.


    == Resources ==
    == Resources ==
    Line 52: Line 123:
    * There is currently one player-made wiki, [https://github.com/iimurpyh/pilot-lua/wiki murpyh's]
    * There is currently one player-made wiki, [https://github.com/iimurpyh/pilot-lua/wiki murpyh's]
    * Some information on parts can be found at [https://was.mawesome4ever.com mawesome's part list site], though some information is inaccurate or not displayed there
    * Some information on parts can be found at [https://was.mawesome4ever.com mawesome's part list site], though some information is inaccurate or not displayed there
    *[https://create.roblox.com/docs/ Roblox creator documentation] contains a load of info on rbx.lua. If you are unfamiliar with lua, or coding in general, it is highly recommended to learn rbx.lua first.


    ==Programming Examples ==
    ==Programming Examples ==

    Revision as of 21:23, 6 July 2023

    Diagram for how to construct a basic computer including a MicroController.

    The game features an in-depth programming language that allows you to write and execute software that can manage and manipulate the state of other objects in-game. The name of this programming language is called Pilot.lua, which is a reference to rbx.lua. It is recommended to learn rbx.lua before you learn pilot.lua. Coding in this game is super helpful, as it allows for much more possibilities and stuff you can do.

    The main parts of programming are:

    • Microcontroller - An object that stores and runs code when triggered by polysilicon and powered. This is the core component of coding, as its the only way to run code in this game.
    • Port - Allows the microcontroller to interact with other objects, trigger and configure, etc. This is also a very important part, because it is the ONLY way to allow microcontrollers to interact with the outside world.
    • Screen - A programmable object that can display user interface objects and UIs such as TextLabel, ImageLabel, etc. This is very important for creating custom UIs and displaying text. However, if you are new to coding and don't understand UIs too much, then it is recommended to just use signs.
    • Disk - Stores values in a dictionary format. It is very useful to store large amounts of info like code and model codes. It is also very useful, as microcontrollers don't carry information across turning on and off, while disks do.
    • EthernetCable (Optional) - Allows you to extend the range of ports, not required to get parts from a Port, although highly recommended if your creation is large, and you need get parts far away from the Port. Note: The EthernetCable needs to be touching the hole on the Port in order to work.
    • (UNSTABLE) Router (optional) - The router is the Antenna of ethernet cables. It does the same thing as ethernet cables, only wireless. This is incredibly useful, as it allows for wireless connections, and allows for parts to be connected from across the region. Note that this is ONLY in unstable.

    Other less-important items in coding include:

    • Modem - Extremely useful for creating makeshift internets of sorts. It allows messages to travel across the entire universe!
    • LifeSensor - Very useful for making smart turrets and other stuff. It is used to return names of players and their Vector3 location.
    • Gyro - while the Gyro is not a coding exclusive part like most, it has a programmable method called gyro:PointAt(vector3 position). This, along with LifeSensor, can make an accurate turret, or if you just want to make the gyro point at a certain place.
    • Keyboard - extremely useful for inputting text, commands, or when attached to a Seat or VehicleSeat, can be used to get keys pressed to make keybinds.
    • Microphone - extremely useful for making chat commands or chat logs of some sort, because its used to get anything said in chat.
    • Instrument - Very useful for giving information to a microcontroller, such as outside temp and position.
    • TouchScreen - A improved version of the Screen, as it allows you to get the X and Y (in offset) of the cursor on the screen.

    The code below is code for a smart turret that takes chat commands and targets players accordingly, with the command "target playername"

    local Gyro = GetPartFromPort(1, "Gyro") -- Gets gyro attached to port 1
    local Microphone = GetPartFromPort(2, "Microphone") -- Gets microphone attached to port 2
    local Commanders = { -- List of usernames allowed to use the smart turret
      ["Robuyasu"] = true;
    }
    -- Connects to the microphone, adding an event to it that will listen for chat input
    Microphone:Connect("Chatted", function(Player, Message) 
    
      -- This simply makes sure that the player speaking is allowed to run a command
      if not Commanders[Player] then return end
    
      if Message:lower():sub(0, 6) == "target" then -- If the message starts with target
        local Victim = Message:sub(8) -- Gets the rest of the message
        Gyro:Configure({Seek=Victim}) -- Configures the seeker to target that person
      end
    end)
    

    There are many functions in Pilot.lua that allow you to interact with other objects. These are the following default functions listed.

    • GetPort(ID) - Returns a port instance that can be used in other functions. It is only really recommended if your going to do something like port:Connect("Triggered")
    • GetPartFromPort(ID or Port Instance, ClassName) Returns a part if found directly attached to a port. An example would be GetPartFromPort(2, "Screen")
    • TriggerPort(ID or Port Instance) - pretty self explanatory, sends a trigger signal from the given port or port instance
    • GetPartsFromPort(ID or Port Instance, ClassName) Returns an array of different parts attached to the Port. In order to use, it is recommended to use ipairs, however, a "for i = number, number do" along with a "Parts[i]" will work too.


    All objects will contain certain programmable properties and functions. However, all instances will contain the following properties and methods:

    • Properties
      • Configurable properties, for example an ionrocket's thrust speed property
      • ClassName, which is simply the name of the object
    • Methods
      • Object:Trigger(), which simply triggers the object
      • Object:Configure({Property=NewValue}), which configures the part to the given dictionary/table
      • Object:Connect, which is similar to roblox connections (part.Touched:Connect). An example includes
     TouchTrigger:Connect("Touched", function() end)
    
    • Events
      • part:Connect("Triggered", function() end)

    Certain parts however will have their own special properties.

    • Screen
      • Methods
        • Screen:CreateElement(string GUIClassName, dictionary Properties), an example includes Screen:CreateElement("TextLabel", {Text = "Hello World!"; TextScaled = true});
        • Screen:ClearElements(), which clears all elements in a gui
    • Disk
      • Methods
        • disk:Write(string Key, any Value) writes a value in the disk with the given key.
        • disk:Read(string Key) Reads the value in the disk with the given key. If there is no value, returns nil.
        • disk:ClearDisk() clears the disk
        • disk:ReadEntireDisk() returns a dictionary of all the values and keys in a disk.
    • Keyboard
      • Events
        • keyboard:Connect("KeyPressed", function(keycode key, string key, string player) end) fires when someone presses a key while sitting on a Seat attached to the keyboard
        • keyboard:Connect("TextInputted", function(string Text, string player) end) fires when someone presses on the Keyboard to open the text menu, and submits text. Note: the keyboard adds an extra character at the end on accident, because you press enter to submit, and so it adds an extra character.

    Small Tutorials

    These tutorials are assuming you know a thing or two about coding already. More are yet to come.

    Screen

    The Screen is a confusing part for beginner programmers, because of all the confusing stuff like UDim2. So, here's an explanation. Screens are a very useful item for displaying information, allowing for much more possibilities then just simply configuring signs. While signs will work for displaying text, it doesn't have nearly as much possibility as screens. Screens can display multiple elements, and have custom size/position. However, when it comes to creating Screen elements, it can be confusing because it uses a whole new data type called UDim2. UDim2 is a data type consisting of 4 values. The order goes XScale, XOffset, YScale YOffset,. What the heck does all that mean?? Well, simply put, Offset is the X or Y size/position of the element in pixels. Scale is the X or Y size/position in screen sizes. What do you mean, "screen sizes"??? 1 scale is equal to the entire size of the screen. 1 XScale is equal to the width of the screen, while 1 YScale is equal to the height of the screen. Scale is very important, as it allows for the ScreenElement to look the same no matter the size of it. In order to make a screen element cover the entire screen, you would put the scale at 1 for both. So what you can do is make the screen size equal to UDim2.new(1, 0, 1, 0). Whats the point of putting the zeros? Is there an easier way to do it? There is an easier way to do it. instead of using UDim2.new, you can use UDim2.fromScale, which is where you only need to put 2 values instead of 4, UDim2.fromScale(1, 1). Before I continue, if you need further help understanding UDim2, go visit the Creator documentation page. Now comes the part where I actually explain how to make a new element. So first to create the element, you need to get the screen from the port.

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    

    Next we would need to clear any elements that are already on the screen using screen:ClearElements().

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    

    Now, to create the element using screen:CreateElement().

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("classname", {properties}) -- creates an element with the given name and properties
    

    Now, we must add the Classname of element we want to create. I will use TextLabel.

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", {}) -- creates an element with the given name and properties
    

    Now, we need to add a few properties.

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", {  -- creates an element with the given name and properties
    Text = "Hi!", --Sets the text to Hi!
    TextScaled = true -- Automatically scales the text to fit the screen
    })
    

    Now, lets use what we learned above, and use UDim2.fromScale to make the size and position.

    local screen = GetPartFromPort(1, "Screen") --Gets the screen
    screen:ClearElements() --clears the screen of any previous elements
    screen:CreateElement("TextLabel", {  -- creates an element with the given name and properties
    Text = "Hi!", --Sets the text to Hi!
    TextScaled = true, -- Automatically scales the text to fit the screen
    Size = UDim2.fromScale(1, 1), --Makes the size cover the whole screen
    Position = UDim2.fromScale(0, 0) --sets the position
    })
    

    Congrats! You made your first Screen element. A few more notes are:

    • Position is the position of the element in the top left corner
    • when doing scale for position, the top is y=0, the bottom is y=1, the left is x=0, the right is x=1. This confuses some people because positive y is actually down, not up.

    Resources

    • There is currently one player-made wiki, murpyh's
    • Some information on parts can be found at mawesome's part list site, though some information is inaccurate or not displayed there
    • Roblox creator documentation contains a load of info on rbx.lua. If you are unfamiliar with lua, or coding in general, it is highly recommended to learn rbx.lua first.

    Programming Examples

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

    Recent changes

  • Axenori • 1 day ago
  • Voivsone • 1 day ago
  • Axenori • 2 days ago
  • Axenori • 2 days ago
  • Cookies help us deliver our services. By using our services, you agree to our use of cookies.