FAQ  •  Register  •  Login

ROBOT ERROR

<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Wed Mar 19, 2014 1:30 am

ROBOT ERROR

  Code:
-- Selects the appropriate weapon to use for a specific target
function selectWeapon(target)
    if(target ~= nil) then
        local weapon = nil
        -- Currently decides based solely on distance away
        if(point.distSquared(target:getPos(),botPos) > 100000) then
            weapon = Weapon.Phaser
        elseif(point.distSquared(target:getPos(),botPos) < 50000)               (point.distSquared(target:getPos(),botPos) > 10000) then
                bot:activateModule(Module.Turbo)
        else
            weapon = Weapon.Burst
                bot:activateModule(Module.Shield)
        end
        return weapon
    end
end
 

This code doesn't work. It's obvious the elseif line is done wrong. explain it please!

I also want to change that else statement into an elseif, see below

else becomes
elseif energy >20% (enough energy to use burst and shield)

else would instead be a run away command
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Wed Mar 19, 2014 3:15 am

Re: ROBOT ERROR

Maybe I'm mistreading this, but...

  Code:
elseif(point.distSquared(target:getPos(),botPos) < 50000)               (point.distSquared(target:getPos(),botPos) > 10000) then
doesn't make any sense. Try removing one of the two comparisons.
<<

Fordcars

User avatar

Posts: 1016

Joined: Fri Apr 20, 2012 3:51 pm

Location: Some city, somewhere

Post Wed Mar 19, 2014 7:08 pm

Re: ROBOT ERROR

or add an "and" or "or" between them
skybax: Why is this health pack following me?
bobdaduck: uh, it likes you.

Return to Bots

Who is online

Users browsing this forum: No registered users and 5 guests