Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

Lua help


Best Answer JohanLiebert , 29 July 2015 - 04:35

Firstly you should be indenting

Secondly, you have two "else" statements for one "if" statement, you can't do that :P

Thirdly, you have one too many "end" statements
loop 
	local enemy = self:findNearestEnemy()
	local distance = self:distanceTo(enemy)

	if distance < 5 then 
		self:attack(enemy)
	else
		self:shield()
	--else   [YOU CAN'T HAVE TWO ELSE'S]
		self:moveXY(41, 34)
		
	end 
	--end    [TOO MANY END STATEMENTS]
end 
Go to the full post »


  • This topic is locked This topic is locked
5 replies to this topic

#1
AbcGetthefkoffme

AbcGetthefkoffme

    Member

  • Members
  • 14 posts

i'm learning lua by playing codecombat.com and i'm having trouble with this 1 level... here is the script, the error i'm getting is end expected? 

 

loop 
local enemy = self:findNearestEnemy()
local distance = self:distanceTo(enemy)
 
if distance < 5 then 
    self:attack(enemy)
else
    self:shield()
else 
    self:moveXY(41, 34)
    
end 
end
end 

  • 0

#2
pleb

pleb

    still not banned :K

  • Donator
  • 426 posts
  • Locationlithuania

whats the level name?


  • 0

#3
AbcGetthefkoffme

AbcGetthefkoffme

    Member

  • Members
  • 14 posts

whats the level name?

stillness in motion.


  • 0

#4
Krystian

Krystian

    Member

  • Contributor
  • 20 posts

Why there are 3 ends? Only one is needed, unless you didn't post whole code  ;)

 

you can't have 2 elses with one if xD

 

if condition then

    code...

elseif condition2

    other code...

else

    last case

end


  • 0

#5
AbcGetthefkoffme

AbcGetthefkoffme

    Member

  • Members
  • 14 posts

Why there are 3 ends? Only one is needed, unless you didn't post whole code  ;)

 

you can't have 2 elses with one if xD

 

if statement then

    code...

elseif statement2

    other code...

else

    last case

end

i needed the 2 else's but i figured it out >.< i just went with a more simple script i guess i was over thinking it. lol


  • 0

#6
JohanLiebert

JohanLiebert

    Advanced Member

  • Members
  • 62 posts
✓  Best Answer
Firstly you should be indenting

Secondly, you have two "else" statements for one "if" statement, you can't do that :P

Thirdly, you have one too many "end" statements
loop 
	local enemy = self:findNearestEnemy()
	local distance = self:distanceTo(enemy)

	if distance < 5 then 
		self:attack(enemy)
	else
		self:shield()
	--else   [YOU CAN'T HAVE TWO ELSE'S]
		self:moveXY(41, 34)
		
	end 
	--end    [TOO MANY END STATEMENTS]
end 

  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users