Menu
Coddy logo textTech

Recap - Player Turn

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

challenge icon

Challenge

Easy

Create a turn-based combat system that checks if a player has enough action points to perform an attack.

Declare the following variables:

  • playerActionPoints with the value 3
  • attackCost with the value 2

Write an if-else statement that:

  • If the player has enough action points (greater than or equal to the attack cost), subtract the attack cost from their action points and print "Attack successful! Action points remaining: X" where X is the remaining points
  • If the player doesn't have enough action points, print “Not enough action points to attack!”

Try it yourself

-- Declare variables
local playerActionPoints = 3
local attackCost = 2

-- TODO: Write your code here

All lessons in Fundamentals