Page 1 of 1

Use Actor:canMove in Actor:move?

Posted: Fri Aug 06, 2010 3:55 pm
by yufra
The following code can be found in engine.Actor:move.

Code: Select all

if not force and map:checkAllEntities(x, y, "block_move", self, true) then return true end
Shouldn't this read like below to take advantage of any over-written Actor:canMove functions?

Code: Select all

if not force and not self:canMove(x, y) then return true end

Re: Use Actor:canMove in Actor:move?

Posted: Fri Aug 06, 2010 4:04 pm
by darkgod
No, not the last parameter (true) in :move(), this tells the combat code to actively try to move, if not set it is just a check.
If you use canMove there then nobody can do melee attacks anymore :)

Re: Use Actor:canMove in Actor:move?

Posted: Fri Aug 06, 2010 4:18 pm
by yufra
The Lua treatment of variable numbers of arguments is new to me, so let us see if I understand correctly. If we execute the following...

Code: Select all

map:checkAllEntities(x, y, "block_move", self, true)
The arg table inside of checkAllEntities is {1=self, 2=true}. This arg table then gets passed on to Entity check...

Code: Select all

function _M:checkAllEntities(x, y, what, ...)
...
			local p = e:check(what, x, y, ...)
At first I thought to myself "block_move" is a value of course, but then I noticed the ActorLife interface...

Code: Select all

function _M:check(prop, ...)
	if type(self[prop]) == "function" then return self[prop](self, ...)
	else return self[prop]
	end
end
And voila! Using the variable names from all the way at the top we get x as x, y as y, self (the Actor trying to move, not the entity already in the tile) as e and true as can_attack.

Code: Select all

function _M:block_move(x, y, e, can_attack)
	-- Dont bump yourself!
	if e and e ~= self and can_attack then
		e:attack(self)
	end
	return true
end
So yes, if the above is all correct I follow your explanation. And now back to Projectile. :D

Re: Use Actor:canMove in Actor:move?

Posted: Fri Aug 06, 2010 4:24 pm
by darkgod
Exactly :)