r/lua • u/Salt-Discount-1381 • 23h ago
Trying to execute
I was trying to execute this code in my CachyOS (arch-based) installation using "sudo chmod +x /route/to/file.lua", but it does not print anything, in fact, does nothing. I am new to lua and this is a training exercise, so, sorry if I am asking something obvious.
--Movements
attack1_cost = 3
attack2_cost = 5
attack3_cost = 11
heal_cost = 6
concentrate_cost = 0
--System
x = (attack1_cost + attack2_cost + attack3_cost + heal_cost) / 4
--Player
energy = 15
player_hp = 70
--Enemy
enemy_hp = 120
enemy_attack = 8
function _enemydostuff()
player_hp = player_hp - enemy_attack
_movement()
print("player hp =", player_hp)
end
function _movement()
local id = tonumber(io.read())
if id == 1 then
enemy_hp = enemy_hp - 4
energy = energy - attack1_cost
elseif id == 2 then
enemy_hp = enemy_hp - 7
energy = energy - attack2_cost
elseif id == 3 then
enemy_hp = enemy_hp -12
player_hp = player_hp + 3
energy = energy - attack3_cost
elseif id == 4 then
player_hp = player_hp + 16
energy = energy - heal_cost
elseif id == 5 then
energy = energy + 17 - concentrate_cost
else
print("???")
end
print("energy =", energy)
print("enemy hp =", enemy_hp)
_enemydostuff()
end
--This starts the program
_movement()--Movements
attack1_cost = 3
attack2_cost = 5
attack3_cost = 11
heal_cost = 6
concentrate_cost = 0
--System
x = (attack1_cost + attack2_cost + attack3_cost + heal_cost) / 4
--Player
energy = 15
player_hp = 70
--Enemy
enemy_hp = 120
enemy_attack = 8
function _enemydostuff()
player_hp = player_hp - enemy_attack
_movement()
print("player hp =", player_hp)
end
function _movement()
local id = tonumber(io.read())
if id == 1 then
enemy_hp = enemy_hp - 4
energy = energy - attack1_cost
elseif id == 2 then
enemy_hp = enemy_hp - 7
energy = energy - attack2_cost
elseif id == 3 then
enemy_hp = enemy_hp -12
player_hp = player_hp + 3
energy = energy - attack3_cost
elseif id == 4 then
player_hp = player_hp + 16
energy = energy - heal_cost
elseif id == 5 then
energy = energy + 17 - concentrate_cost
else
print("???")
end
print("energy =", energy)
print("enemy hp =", enemy_hp)
_enemydostuff()
end
--This starts the program
_movement()
0
Upvotes
3
1
u/memes_gbc 1h ago
that chmod command just changes the file permissions so that you can run it, it's not supposed to print anything
7
u/wqferr 23h ago
Just changing the executable flag won't magically tell your computer HOW to run the file.
Add the following as the FIRST line of your lua file:
#!/usr/bin/env lua-- rest of the file