How do i use "print()"?

One morning, my mom woke me up with tears streaming down her face. She told me that my dad had been killed in a car accident on his way to work. I couldn’t believe it. My dad, the genius programmer, was gone. I felt like my world had crumbled beneath my feet.

A year later, I remembered something my dad had promised to teach me. It was something he called “print()”. My dad had said I wasn’t ready to learn it yet. He promised that one day, he would teach me how it worked and I would be able to use it in my coding.

So I would like to ask if you know about “print()” and how it works?

11 Likes

This post peaks. Absolutely magnificent

1 Like

Sad for you, but anyways: https://youtu.be/JpeE1RxNVho?si=f-Jdwta5EzZ_nKzH

1 Like

Well it’s quite simple to do. First you connect your IDE to your printer on the same WiFi connection and then you call print() with some text if you want the printed page to have some text. You can also input an image or a word document to print amazing papers that will impress your teachers. Don’t try to input video files though, printing videos will crash the CPU that’s running our world.

4 Likes

The print() function in Luau, the scripting language predominantly used in Roblox game development, is a cornerstone tool for developers, offering a versatile means of communicating information. Its role extends beyond simple text output; it serves as a crucial aid in debugging, testing, and comprehending the intricate dynamics of code execution.

At its most basic level, developers can employ print() to display static text, providing essential insights into the flow of their program. For example, a straightforward call like print("Hello, Luau!") would output the string “Hello, Luau!” to the console, enabling developers to mark specific points in their code and monitor its progression.

The true power of the print() function becomes evident when dealing with dynamic information. Developers can concatenate strings and variables within the function call, allowing them to output changing values and perform complex calculations. Consider the example where a variable number is assigned the value 42: print("The answer is: " .. number). Here, the console output would dynamically display “The answer is: 42,” showcasing how print() adapts to the evolving state of the program.

Moreover, Luau’s print() function supports the simultaneous display of multiple values by separating them with commas. This feature is invaluable for presenting a
comprehensive snapshot of a program’s state. For instance, a script featuring

local name = "John" 
local age = 25
 print("Name:", name, "Age:", age)

would output Name: John Age: 25 in the console. This structured approach facilitates the analysis of different facets of the program, enhancing the developer’s ability to understand and troubleshoot complex systems.

In essence, mastering the intricacies of the print() function in Luau goes beyond the rudimentary task of displaying text. It becomes a tool for dynamic communication, offering developers insights into the evolving nature of their code. Whether it’s conveying static information, incorporating dynamic values, or presenting a multitude of variables, print() stands as an indispensable asset for developers navigating the challenges of Roblox game development, contributing significantly to their debugging and problem-solving capabilities.

Hopefully this helps!

3 Likes

print(...)
Displays all values in either Studio and/or Roblox Developer Console

... means any number of values past this point

Code sample:

local x = 1
local y = 2

print(x + y)

When a table gets output, Roblox Studio gets all values from the table and formats them.
Example:

print({})

-- Roblox Studio: {}
-- Normal Developer Console (F9 or /console in chat): table: 0x56ed5f1c3ae0e584

The reason we get table: 0x56ed5f1c3ae0e584 in the Developer Console and not Studio is because print tostrings all values passed. This means that print goes through all values and tostrings them. For example, 1 gets turned to “1”, nil gets turned to “nil”, and {} gets turned into “table: 0x[Memory address]”. You can also achieve the same behaviour when using userdata (newproxy() → “userdata: 0x[Memory address]”)

You can do this yourself using print(tostring({}))

You can also use metatables to change the output of tables.
Example:

local x = setmetatable({}, {
    __tostring = function()
        return "This will get displayed instead of {}!"
    end
})

print(x)

Learn more about print here!

1 Like