Menu
Coddy logo textTech

Calling a Function

Part of the Fundamentals section of Coddy's Lua journey — lesson 51 of 90.

Creating a function is only the first step - to make the code inside the function run, you need to call the function.

Here's the key concept: declaring a function doesn't execute its code. Think of it like writing down a recipe - the recipe exists, but no food gets cooked until you actually follow the instructions.

To call a function, simply write its name followed by parentheses:

function sayHello()
    print("Hello there!")
end

sayHello()  -- This calls the function
challenge icon

Challenge

Easy

Create a player status notification system by declaring and calling a function that displays important game information. First, declare a function named displayPlayerStatus that prints "Player is online and ready!". After declaring the function, call it twice to simulate checking the player status at two different moments in the game.

Cheat sheet

To call a function, write its name followed by parentheses:

function sayHello()
    print("Hello there!")
end

sayHello()  -- This calls the function

Declaring a function doesn't execute its code - you must call it to run the code inside.

Try it yourself

-- TODO: Write your code here
-- Declare the displayPlayerStatus function
-- Then call it twice
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals