1

Ok, so I am trying to create a text-based adventure game. I am currently creating the attack system. Here is the code

start = io.read()
if start == "start" then
    ma1 = "jab your opponent"
    ma2 = "hook your oppenent"
    fa1 = "kick your oppenent"
    ha1 = "headbutt your oppenent"
    --Melee weapon
    mw1 = "fist1"
    mw2 = "fist2"
    foot = "Kick"
    head = "headbutt"
    --Magic attacks
    ms1 = "none"
    ms2 = "none"
    ms3 = "none"
    ms4 = "none"
    --Gadgets
    bow = "none"
    gun = "none"
    sg = "none"
    function atk()
        io.write("Do you use melee(1), magic(2), or tech(3)?", "\n")
        ac = io.read()
        if ac == "1" then
            io.write("Do you", ma1,",", ma2, ",",fa1,",or",ha1"?", "\n")
        end
    end
end
print(atk())

Every time I run this it outputs this:

lua: jdoodle.lua:25: global 'ha1' is not callable (a string value)
stack traceback:
    jdoodle.lua:25: in function 'atk'
    jdoodle.lua:29: in main chunk
    [C]: in ?

So if you have any solutions thank you.

Shatow
  • 17
  • 4
  • 1
    comma is missed `ha1,"?"` – Mike V. Feb 17 '22 at 13:16
  • 1
    You forgot a comma turning `ha1, "?"` into `ha1"?"`. as you can omit parenthesis for a function call with a single literal string argument, `ha1"?"` is equivalent to `ha1("?")`. therefor you're attempting to call the string value `ha1`. add the comma to resolve the issue. you might also make yourself familiar with the concatenation operator `..` to get prettier prints. you function `atk` does not return a value it printing the function call doesn't make sense. just call the function – Piglet Feb 17 '22 at 13:19
  • thank you piglet I will do my best to familiarize myself with the concatenation operator and thank you for responding to this and my other questions. – Shatow Feb 17 '22 at 13:36

1 Answers1

0

You missed a comma:

start = io.read()
if start == "start" then
    --body
        if ac == "1" then
            io.write("Do you", ma1, ", ", ma2, ", ", fa1, ", or", ha1, "?", "\n")
        end
end
print(atk())
Corotyest
  • 31
  • 3