Im trying to make a simple guessing game in lua for the ti nspire cx (code below) how do i convert this to a .tns file? Thanks!
Code:
Code:
-- Number Guessing Game
-- Initialize variables
local targetNumber = math.random(1, 100)
local guess = 0
local attempts = 0
local maxAttempts = 10
-- Function to display a message
function displayMessage(message)
print(message)
end
-- Function to check the player's guess
function checkGuess(playerGuess)
attempts = attempts + 1
if playerGuess < targetNumber then
displayMessage("Too low! Try again.")
elseif playerGuess > targetNumber then
displayMessage("Too high! Try again.")
else
displayMessage("Congratulations! You guessed it right!")
return true
end
if attempts >= maxAttempts then
displayMessage("Sorry, you've run out of attempts. The number was " .. targetNumber)
return true
end
return false
end
-- Main game loop
function gameLoop()
displayMessage("Welcome to the Number Guessing Game!")
displayMessage("Guess a number between 1 and 100.")
while true do
displayMessage("Enter your guess: ")
guess = tonumber(io.read())
if guess then
local gameOver = checkGuess(guess)
if gameOver then
break
end
else
displayMessage("Please enter a valid number.")
end
end
end
-- Start the game
gameLoop()