Log In  


Hi everyone,

I'm working on a little robotic sumo game for a friend after seeing an IRL video about it. I decided to include a 4-player mode, because I like multiplayer games.

I want players to score only if they're the ones who knocked the player out of the arena when play is halted (basically like in Super Smash Bros), but I'm having trouble recording that information.

Here's the relevant code:

--main game loop
for p in all(players) do
 check_hit(p)
 --other stuff
end

function check_hit(p)
 for o in all(players) do
  if circlehit(p,o) and  --Basic collision function.
   p.col~=o.col then     --This line is meant to keep players from hitting themselves.
    p.lasthit=o.col      --Here, "col" is the player's color, and "lasthit" is who last hit them.
  end                    --In another function, I award points to the player whose color
 end                     --matches the "lasthit" value of the ko'd player.
end

I need to prevent players from "hitting" themselves, because otherwise they would score when they're knocked from the ring. (If I remove the "p.col~=o.col" line, that's exactly what happens.)

But right now, scores don't register properly because of a bug with check_hit(p). My testing tells me there's something wrong with this function alone -- it's not recording a "lasthit" value as currently written. I'm not sure whether the problem is the "p.col~=o.col" comparison, or running a for loop within a for loop, or what.

Does anyone have a sense of what I've done wrong, or suggestions for doing this more efficiently? Thank you in advance for any and all advice.



2

I would start by no testing p against itself:

function check_hit(p)
 for o in all(players) do
  if p!=o then
   — check for collisions 
   ...
  end
end

Thank you for the suggestion, freds72. Unfortunately, this seems to encounter the same issue as before.

Is there something about no-testing within a nested for loop that causes this issue, I wonder?


Oh! It seems the problem was in a different physics function I was using. The function that bumps the sumo-bots kicks in before check_hit(p), so they were always moved out of the way before check_hit(p) could take effect.

Thanks for your help!



[Please log in to post a comment]