Your Potential First Line of Code? Learn functions and printing. (How to tell the robot to eat a pancake)

Hello!

So I don’t know if this is the right category. But I wanted to teach some newer users how to lua code basic functions with some comedic background by our friend Steve who wants to eat his pancake but in coding!

Today we will be working on making our first line of code in Luau which is the programming language that is used in Roblox Studio. We will learn basic functions and printing on Luau.

What is a function?

Imagine Lua is a little chef in a kitchen.
If you want the chef to cook something later, you must teach them the recipe.

That recipe is called a function.

For example:

Lua! I have a recipe for you

function makeSandwich()

Lua then write down your instructions

print("Making a sandwich...")
print("Adding cheese...")
print("Sandwich complete!")

Inside the function, you put whatever you want Lua to do

Then you can close the code by using

end

To make lua actually use the recipe

makeSandwich()

So here is a quick summary of how to use functions to make our friend Steve enjoy his pancake.

Hope you enjoy!


-- Function: Robot picks up the pancake
function pickUpPancake()
    print("ACTION: Acquiring pancake from plate.")
end

-- Function: Robot analyzes the pancake
function analyzePancake()
    print("ACTION: Conducting structural and quality analysis of pancake.")
end

-- Function: Robot simulates taking a bite
function takeBite()
    print("ACTION: Simulating controlled bite of pancake.")
end

-- Function: Robot completes the task
function finishPancake()
    print("ACTION: Pancake consumption sequence completed successfully.")
end

-- Execute the sequence in order
pickUpPancake()
analyzePancake()
takeBite()
finishPancake()

print("SYSTEM: Pancake Protocol Complete.")

4 Likes

First of all you must tell begginers that roblox uses Luau (modified Lua) to avoid further confusion
Next add ```lua to add code highlighting
You should right awey teach begginers how to declear function properly:

local function NameHere()
--code
end

Add more information please with explanation since tutorial is very hollow for now.

4 Likes

The code to call functions is:

local function Myfunction()
print("Function Running")
end

Myfunction()  -- calls The function

An advanced function

local function MyAdvancedFunction(Number1, Number2)
Result = Number1 + Number2
Print(Result)   --It will print 12
end

MyAdvancedFunction(7, 5)
1 Like