Sacred Statue / Null/Nil Concept In General

I am trying to figure out how to execute a line of code once there are no (alive) enemies on the map at the time. I do not know how to use null or nil yet. I did see another thread suggest trying enemies = null or something like that, but even with the best glasses in the game and making sure I properly defined “enemies”, I do not believe it worked.

I am practicing all the languages on offer, but I main LUA. Any advice appreciated, but please specify what language and anything specific to it if possible.

I will share just a snippet of my code below so we can see the general idea I’ve got going on. Feel free to work off this or offer something from scratch. All I’m looking for is the ability to tell the game to “do X when there are no enemies”.

Again, this is a pared down version of my code:

while true do
local enemy = hero:findNearestEnemy()
local enemies = hero:findEnemies()
    if enemy then
          if hero:isReady("bash") then
               hero:bash(enemy)
          hero:attack(enemy)
          end
    else if (enemies = nil) then
        hero:moveXY(62, 65)
    end
    end
end

To execute a line of code when there are no (alive) enemies on the map, you can use the length of the enemies array to check if it’s empty. In Lua, you can use the #enemies operator to get the length of the array, and if it’s zero, that means there are no enemies. Here’s how you can modify your code to achieve this:

while true do
    local enemies = hero:findEnemies()

    if #enemies > 0 then
        local enemy = hero:findNearestEnemy()
        if enemy then
            if hero:isReady("bash") then
                hero:bash(enemy)
            end
            hero:attack(enemy)
        end
    else
        -- No enemies found, so do something when there are no enemies.
        hero:moveXY(62, 65)
    end
end

In this modified code, the enemies array is populated with all the enemies on the map. If the length of the enemies array is greater than zero, it means there are enemies, and the hero will attack or perform other actions as needed. If the length of the enemies array is zero (no enemies), the hero will move to the specified location (in this case, (62, 65) ).