Page 2 of 2

Re: Need help with Bump.lua Filters

Posted: Thu Aug 01, 2024 8:36 pm
by cip
dpkgluci wrote: Thu Aug 01, 2024 8:21 pm I printed it but got nil, and the ground tile above the spike is impossible since the player is standing on top of a spike, it doesnt touch any ground tiles

But I resolved this! I used the type (class) property! it's not a custom property, but you can put strings on it, so I marked all my spike boxes with spike and all my ground ones with ground and now with this filter

Code: Select all

local collidablefilter = function(_, other)
  if other.type == "spike" then
    return "cross"
  elseif other.type == "ending" then
    return "slide"
  elseif other.type == "coin" then
    return "cross"
  else
    return "slide"
  end
end
Awesome, happy it worked out!

Re: Need help with Bump.lua Filters

Posted: Thu Aug 01, 2024 9:55 pm
by dpkgluci
Hi again! I am having a lot of trouble figuring out how to call a function when certain collision type occurrs, I am trying to call the function death() (which I already coded and works) when the player touches the spikes. how is it made most of the time?

Re: Need help with Bump.lua Filters

Posted: Thu Aug 01, 2024 10:54 pm
by MrFariator
If you consider my first post in this thread, when running world:move on your player, you'd do:

Code: Select all

local newX, newY, cols, len = world:move (player, targetX, targetY, playerFilter)

for i = 1, len do
  local other = cols[i].other
  if other.type == "isPlayerKillingCollision" then
    death()
    return
  end
end
If it's another object (like a bullet) colliding with the player, you can do:

Code: Select all

for i = 1, len do
  local other = cols[i].other
  if other.type == "isPlayer" then
    other:death() -- assuming you can access the death function on the player object like this
    return
  end
end
Basically, let world:move resolve, and then do the appropriate things when looping through the collisions (dying, taking damage, touching a goal, touching collectibles, etc).

Re: Need help with Bump.lua Filters

Posted: Thu Aug 01, 2024 11:08 pm
by dpkgluci
The code crashes, I don't know what to do

the for seems to be malformed, love says

Code: Select all

Error: Syntax error: assets/scripts/player.lua:133: 'in' expected near 'do'

Re: Need help with Bump.lua Filters

Posted: Thu Aug 01, 2024 11:14 pm
by dpkgluci
Oh I just named some variables differently. Thanks mrfariator!!