no errors, but my hero simply won’t attack, went through other forums, and found someone with the same issue who simply reloaded a bunch of times, and one who switched heros, neither of which have worked for me
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack("munchkin")
if enemy.type == "brawler"
then self:say("come here!")
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
hero:moveXY(30, 34)
end
end
end
end
end
Hi @Stroogles, welcome to the Discourse! Thanks for formatting your code.
I don’t know Lua, but there are a few issues that I can help you with:
The munchkins are not all called “munchkin”, yet you used a string. Since you want to attack them, use enemy
(without quotation marks/inverted commas) in place of "munchkin"
You’re also missing end
at the end of both if
checks in the dealEnemy
function, and have redundant end
keywords after the while True
loop.
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack(enemy)
end
if enemy.type == “brawler”
then self:say("come here!")
end
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
hero:moveXY(30, 34)
end
end
end
yields the same results, a little confused what you’re trying to get at with the munchkin thing but I tried, though “munchkin” should already be labled as a specific enemy type, and something similar worked in the last level.
forgot to format correctly
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack(enemy)
end
if enemy.type == "brawler"
then self:say("come here!")
end
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
hero:moveXY(30, 34)
end
end
end
Didn’t you receive this error?
Also, try replacing the second if
with elseif
, remove the end
on line 6, and add another end
to the end of the function (at the moment you end the if
loop, but not the function)
no errors at all,
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack("munchkin")
elseif enemy.type == "brawler"
then self:say("come here!")
end
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
hero:moveXY(30, 34)
end
end
end
still has the same results, no action (changed it back to (“munchkin”) example)
It’s weird that you aren’t getting any errors… Place a hero.say(“debug”) as the first action in the function to check if it’s running that
tried using both hero:say and self:say, neither worked (nothing was said)
Oh, remember to add the second end to the function
correct me if I’m wrong, but you’re only ending the if/elseif at the moment
just tested it, messages work if I put them before the function, not in
like this?
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack("munchkin")
elseif enemy.type == "brawler"
then self:say("come here!")
end
end
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
hero:moveXY(30, 34)
end
end
I just get a red X
I just tried the code again. I changed "munchkin"
to enemy
and it worked fine.
with the original code? or most recent one I gave?
The most recent one
I’m still given the X with “that, arguments[2]”
function dealEnemy(enemy)
if enemy.type == "munchkin"
then self:attack("munchkin")
if enemy.type == "brawler"
then self:say("come here!")
while true do
local enemy = hero:findNearestEnemy()
if enemy then
dealEnemy(enemy)
else
self:say("no enemies nearby")
end
end
end
end
end
changed “move” to self:say(“no enemies nearby”), and no message is given
Hm, it runs with no problems for me
I don’t think that code will run if the hero doesn’t attack, as there’ll always be enemies.
Do you have any other heroes you could use? I’ve seen a few other solutions where they just changed the hero and it was fine
apparently there’s a limit on new users so I had to go run and make a new account, but I just tried using all of my available hero’s with no luck
Oh
I’m really sorry that I can’t help, I’ll look into it further and update you if I find anything.