Use Actor:canMove in Actor:move?

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Use Actor:canMove in Actor:move?

#1 Post 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
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Use Actor:canMove in Actor:move?

#2 Post 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 :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Use Actor:canMove in Actor:move?

#3 Post 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
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Use Actor:canMove in Actor:move?

#4 Post by darkgod »

Exactly :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply