×
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
    No edit summary
    (More context about rbx.lua, i added i so people know that rbx.lua is a nickname for Luau)
     
    (36 intermediate revisions by 17 users not shown)
    Line 1: Line 1:
    [[File:8282717dfaf08e4c024e6ec7a3d9b700.gif|thumb|A flappy bird arcade machine, made by iiMurpyh|302x302px]]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.]]Waste of Space features a programming language named '''Pilot.lua'''. Pilot.lua lets players manipulate the states of objects in-game. As Pilot.lua is a superset of [https://luau-lang.org/ Luau] – Roblox' superset of [https://en.wikipedia.org/wiki/Lua_(programming_language) Lua] 5.1 '''' learning Luau (or at least Lua 5.1) first would be beneficial.


    Documentation for all the parts can be found here [https://github.com/iimurpyh/pilot-lua/wiki].
    The main parts of programming are
    Important parts for programming:
    * 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.


    *[[Microcontroller]] - Runs code when triggered by Polysilicon if it is powered. This is an essential part, as it is the only way to run code.
    The code below is code for a smart turret that takes chat commands and targets players accordingly, with the command "target playername"
    *[[Port]] - Allows the Microcontroller to interact with other objects, configure them, and send triggers. While not strictly essential, it is still a core part of programming as it is the only way for a Microcontroller to interact with its surroundings.
    local Gyro = GetPartFromPort(1, "Gyro") -- Gets gyro attached to port 1
    *[[Screen]] - Displays user interface objects on its surface using Gui elements (such as TextLabel, Button, ..). It is one of the most common ways to provide the user with feedback as it is able to display it in a clear, visual way. It can be to a certain extent supplemented with the much easier to program [[Sign|signs]].
    local Microphone = GetPartFromPort(2, "Microphone") -- Gets microphone attached to port 2
    *[[Disk]] - Stores values in a [https://create.roblox.com/docs/education/coding-5/intro-to-dictionaries dictionary] format. Can store large amounts of data like code and [[Model Builder|model codes]]. Data stored on a disk is permanent, as opposed to variables on a microcontroller (which are lost when the microcontroller is powered off, or the server is restarted).
    *[[EthernetCable]] (optional) - Allows Ports to reach further when placed touching the hole of the port, similar to how a wire allows power to reach further.
    *(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:
    local Commanders = { -- List of usernames allowed to use the smart turret
    *[[Modem]] - Allows for cross-region message passing and communication with arbitrary www domains (Sends GET and or POST requests to either the WOS internet, or the real (www) one). Allows for the creation of an internet of sorts. See the article for more details.
    Robuyasu = true;
    *[[LifeSensor]] - Returns the names of players and their Vector3 location, if they are within its range. Can be used to make, for example, smart turrets.
    }
    *[[Gyro]] - Not programming-exclusive, though still widely used as 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]] - Used for inputting text, commands, or when attached to a [[Seat]] or [[VehicleSeat]], can be used to get keys pressed to make keybinds.
    *[[Microphone]] - Retrieves chat messages. Can be used for chat logs or chat commands.
    *[[Instrument]] - Measures physical properties such as temperature or velocity.
    *[[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. Note that you can use buttons on Screens for User input.


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


    -- This simply makes sure that the player speaking is allowed to run a command
    There are many functions in Pilot.lua that allow you to interact with other objects. These are the following default functions listed.
    if not Commanders[Player] then return end
    * GetPort(ID) - Returns a port instance that can be used in other functions.
    * 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)


    if Message:lower():sub(0, 6) == "target" then -- If the message starts with target
    All objects will contain certain programmable properties and functions. However, all instances will contain the following properties:
    local Victim = Message:sub(8) -- Gets the rest of the message
    * Configurable properties, for example an ionrocket's thrust speed property
    Gyro:Configure({Seek=Victim}) -- Configures the seeker to target that person
    * ClassName, which is simply the name of the object
    end
    * Object:Trigger(), which simply triggers the object
    end)
    * Object:Configure({Property=NewValue}), which configures the part to the given dictionary/table
    </syntaxhighlight>
    * Object:ConnectToEvent, which is similar to roblox connections (part.Touched:Connect). An example includes TouchTrigger:ConnectToEvent("Touched", function() end)
    There are many functions in Pilot.lua that allow you to interact with other objects:

    *<code>GetPort(ID)</code> - Returns a port instance that can be used in other functions. It is only really recommended if your going to do something like <code>port:Connect("Triggered")</code>
    *<code>GetPartFromPort(ID or Port Instance, ClassName)</code> Returns a part if found directly attached to a port. An example would be GetPartFromPort(2, "Screen")
    *<code>TriggerPort(ID or Port Instance)</code> - pretty self explanatory, sends a [[Button|trigger signal]] from the given port or port instance
    *<code>GetPartsFromPort(ID or Port Instance, ClassName)</code> 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 <code>'''for i =''' number, number do</code> along with <code>Parts[i]</code> 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
    **<code>ClassName</code>, 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, connects a function to an object's event

    *Events
    **part:Connect("Triggered", function)
    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
    Alternatively, a wiki exclusive to Pilot.lua can be found here: https://github.com/iimurpyh/pilot.lua/wiki. You can also visit https://wos.mawesome4ever.com for a list of all the parts, a brief description and their programmable properties/events which are all pulled using a script so there might be a few kinks.

    *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.

    ==Tutorials==
    These tutorials are assuming you know a thing or two about coding already. More are yet to come.
    ===Events===
    One of the most important parts about programming in WoS is events. Events allow you to get player input, detect when something happened, and more. For example, if you are using the [[Microphone]], in order to get when a player has talked, you need to use the chatted event. A full list of events can be found [https://github.com/iimurpyh/pilot-lua/wiki here]. To get an event, you need to first do the connect method on the part, like this; microphone:Connect(). Within the parenthesis, you need to put two parameters. The first one is simple, just put the name of the event within a string (example: "Chatted"). As the second parameter, we put the function we want it to run when the event happens. This is known as a [https://en.wikipedia.org/wiki/Callback_(computer_programming) callback]. Basically, its when you pass a function as a parameter to another function. In this example, we want the :Connect() method to run a function whenever the "Chatted" event happens. In that second parameter, we can reference an already existing function, or make a function within the parameter. Here is our code so far:
    <syntaxhighlight lang="lua" line="1">
    local microphone = GetPartFromPort(1, "Microphone") --this gets the microphone object
    microphone:Connect("Chatted", function() --so we call the connect method, then we tell it to run the function whenever it detects the event
    print("Someone talked!!!")
    end)--we need to end the function, and close the open parenthesis
    </syntaxhighlight>
    Now, this isn't very useful on its own. We have no way of telling what the person even said! All we know is when someone talked. However, we are in luck. When the connect method calls the function, it also passes the parameters along with the function (once again, all the events and what they return can be found [https://github.com/iimurpyh/pilot-lua/wiki here]). In the case of the chatted event, it returns the players name, and the message they sent. Here is the example code:
    <syntaxhighlight lang="lua" line="1">
    local microphone = GetPartFromPort(1, "Microphone") --this gets the microphone object
    microphone:Connect("Chatted", function(player, message) --so we call the connect method, then we tell it to run the function whenever it detects the event
    print(player.. " Said: ".. message) --print what was said and who said it (eg. Playername Said: Hello!)
    end)--we need to end the function, and close the open parenthesis
    </syntaxhighlight>
    ===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.
    ===Modem===
    <!--If someone knows anything about the post and get requests stuff, PLEASE put it down below-->
    The [[Modem]] allows you to send messages across the entire universe! You could even create a makeshift internet of sorts with it! This being said, it seems like a scary and confusing prospect for new programmers. But the reality is, that it is very simple. There are two main things you need to know to make a messaging system or something like that. First is the SendMessage method. This is very simple. It sends a message across the universe. All you need to put in the method's parameters is the message you with to send, and the [[Modem]] ID you wish to send it on. Here is an example:
    <syntaxhighlight lang="lua" line="1">
    local modem = GetPartFromPort(1, "Modem")--gets the modem object
    modem:SendMessage("Hello WoS", 1) --sends the message "Hello WoS" on the Modem
    </syntaxhighlight>
    ''Well you can send messages, but how do you receive?''
    You receive messages using an event. If you are unfamiliar with events, please read the tutorial above about events. The event name is MessageSent. It fires when a message is received from a modem with the same ID. It only provides a singular parameter, and that is the data that was sent. Here is an example of a modem that picks up messages and writes it to a sign.
    <syntaxhighlight lang="lua" line="1">
    local modem = GetPartFromPort(1, "Modem")--gets the modem object
    local sign = GetPartFromPort(2, "Sign")--gets the sign object
    modem:Connect("MessageSent", function(message)
    sign:Configure({SignText=message})--write the message to a sign
    end)
    </syntaxhighlight>
    There you go! You have just made a simple messaging system. You can expand on this by using [[Keyboard|Keyboards]] to send messages, or use screens to make a nice looking UI.

    Another method is the RealPostRequest, it enables you to send post requests to real websites such as google. Here's an example:

    <syntaxhighlight lang="lua" start="1">
    local Modem = GetPartFromPort(1,"Modem")
    local Sign = GetPartFromPort(1,"Sign")

    local Payload = JSONEncode({"Data",1,2,3})

    local Data, Success = Modem:RealPostRequest("http://CustomLinkHere.com",Payload,false,nil,{["Content-Type"]="application/json"})
    if Success then
    Sign:Configure({SignText=Payload})
    end
    </syntaxhighlight>Sadly, the RealGetRequest does not work. So you have to use the post requests.

    If you want to use the RealPostRequest for sending data to your computer then you will have to use third party resources. (i.e. website hosting) how ever, learn Luau first, you will need some LUAU experience or lua 5.1 experience, learn Lua 5.1 then Luau then pliot.lua.

    == Resources ==

    * 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://wos.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. if you do NOT know what rbx.lua IS, it is a nickname for Luau.

    ==Programming Examples ==
    [[File:FlappyBirdGif.gif|thumb|A flappy bird arcade machine, made by iiMurpyh|302x302px|alt=|center]]

    [[Category:Tutorials]]
    [[Category:Tutorials]]
    [[Category:Mechanics]]
    __INDEX__

    Latest revision as of 21:38, 15 June 2024

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

    Waste of Space features a programming language named Pilot.lua. Pilot.lua lets players manipulate the states of objects in-game. As Pilot.lua is a superset of Luau – Roblox' superset of Lua 5.1 learning Luau (or at least Lua 5.1) first would be beneficial.

    Documentation for all the parts can be found here [1]. Important parts for programming:

    • Microcontroller - Runs code when triggered by Polysilicon if it is powered. This is an essential part, as it is the only way to run code.
    • Port - Allows the Microcontroller to interact with other objects, configure them, and send triggers. While not strictly essential, it is still a core part of programming as it is the only way for a Microcontroller to interact with its surroundings.
    • Screen - Displays user interface objects on its surface using Gui elements (such as TextLabel, Button, ..). It is one of the most common ways to provide the user with feedback as it is able to display it in a clear, visual way. It can be to a certain extent supplemented with the much easier to program signs.
    • Disk - Stores values in a dictionary format. Can store large amounts of data like code and model codes. Data stored on a disk is permanent, as opposed to variables on a microcontroller (which are lost when the microcontroller is powered off, or the server is restarted).
    • EthernetCable (optional) - Allows Ports to reach further when placed touching the hole of the port, similar to how a wire allows power to reach further.
    • (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 - Allows for cross-region message passing and communication with arbitrary www domains (Sends GET and or POST requests to either the WOS internet, or the real (www) one). Allows for the creation of an internet of sorts. See the article for more details.
    • LifeSensor - Returns the names of players and their Vector3 location, if they are within its range. Can be used to make, for example, smart turrets.
    • Gyro - Not programming-exclusive, though still widely used as 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 - Used for inputting text, commands, or when attached to a Seat or VehicleSeat, can be used to get keys pressed to make keybinds.
    • Microphone - Retrieves chat messages. Can be used for chat logs or chat commands.
    • Instrument - Measures physical properties such as temperature or velocity.
    • 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. Note that you can use buttons on Screens for User input.

    As an example, 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:

    • 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 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, connects a function to an object's event
    • Events
      • part:Connect("Triggered", function)

    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.

    Tutorials[edit | hide all | hide | edit source]

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

    Events[edit | hide | edit source]

    One of the most important parts about programming in WoS is events. Events allow you to get player input, detect when something happened, and more. For example, if you are using the Microphone, in order to get when a player has talked, you need to use the chatted event. A full list of events can be found here. To get an event, you need to first do the connect method on the part, like this; microphone:Connect(). Within the parenthesis, you need to put two parameters. The first one is simple, just put the name of the event within a string (example: "Chatted"). As the second parameter, we put the function we want it to run when the event happens. This is known as a callback. Basically, its when you pass a function as a parameter to another function. In this example, we want the :Connect() method to run a function whenever the "Chatted" event happens. In that second parameter, we can reference an already existing function, or make a function within the parameter. Here is our code so far:

    local microphone = GetPartFromPort(1, "Microphone") --this gets the microphone object
    microphone:Connect("Chatted", function() --so we call the connect method, then we tell it to run the function whenever it detects the event
    print("Someone talked!!!")
    end)--we need to end the function, and close the open parenthesis
    

    Now, this isn't very useful on its own. We have no way of telling what the person even said! All we know is when someone talked. However, we are in luck. When the connect method calls the function, it also passes the parameters along with the function (once again, all the events and what they return can be found here). In the case of the chatted event, it returns the players name, and the message they sent. Here is the example code:

    local microphone = GetPartFromPort(1, "Microphone") --this gets the microphone object
    microphone:Connect("Chatted", function(player, message) --so we call the connect method, then we tell it to run the function whenever it detects the event
    print(player.. " Said: ".. message) --print what was said and who said it (eg. Playername Said: Hello!)
    end)--we need to end the function, and close the open parenthesis
    

    Screen[edit | hide | edit source]

    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.

    Modem[edit | hide | edit source]

    The Modem allows you to send messages across the entire universe! You could even create a makeshift internet of sorts with it! This being said, it seems like a scary and confusing prospect for new programmers. But the reality is, that it is very simple. There are two main things you need to know to make a messaging system or something like that. First is the SendMessage method. This is very simple. It sends a message across the universe. All you need to put in the method's parameters is the message you with to send, and the Modem ID you wish to send it on. Here is an example:

    local modem = GetPartFromPort(1, "Modem")--gets the modem object
    modem:SendMessage("Hello WoS", 1) --sends the message "Hello WoS" on the Modem
    

    Well you can send messages, but how do you receive? You receive messages using an event. If you are unfamiliar with events, please read the tutorial above about events. The event name is MessageSent. It fires when a message is received from a modem with the same ID. It only provides a singular parameter, and that is the data that was sent. Here is an example of a modem that picks up messages and writes it to a sign.

    local modem = GetPartFromPort(1, "Modem")--gets the modem object
    local sign = GetPartFromPort(2, "Sign")--gets the sign object
    modem:Connect("MessageSent", function(message)
    sign:Configure({SignText=message})--write the message to a sign
    end)
    

    There you go! You have just made a simple messaging system. You can expand on this by using Keyboards to send messages, or use screens to make a nice looking UI.

    Another method is the RealPostRequest, it enables you to send post requests to real websites such as google. Here's an example:

    local Modem = GetPartFromPort(1,"Modem")
    local Sign = GetPartFromPort(1,"Sign")
    
    local Payload = JSONEncode({"Data",1,2,3})
    
    local Data, Success = Modem:RealPostRequest("http://CustomLinkHere.com",Payload,false,nil,{["Content-Type"]="application/json"})
    if Success then
     Sign:Configure({SignText=Payload})
    end
    

    Sadly, the RealGetRequest does not work. So you have to use the post requests.

    If you want to use the RealPostRequest for sending data to your computer then you will have to use third party resources. (i.e. website hosting) how ever, learn Luau first, you will need some LUAU experience or lua 5.1 experience, learn Lua 5.1 then Luau then pliot.lua.

    Resources[edit | hide | edit source]

    • 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. if you do NOT know what rbx.lua IS, it is a nickname for Luau.

    Programming Examples[edit | hide | edit source]

    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 • 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.