Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Argeus

Pages: [1]
1
This may be user error and not a bug because I am not a programmer by trade or experience.  Apologies in advance.

I have a side project in which I am having a problem where "get_facing_entity()" only works once.  In the project I have a custom entity that follows the hero around.  This custom entity needs to be able to detect certain map entities, namely movement entities like "stairs" and "jumpers."  The relevant code is below:

Code: [Select]
--ALLOWING THE CUSTOM_ENTITY TO INTERACT WITH "JUMPER" ENTITIES
custom_entity:set_can_traverse("jumper", jumper_found)

--FUNCTION SETUPS

--TO END ANY CURRENT MOVEMENTS IF APPLICABLE
function end_movement()
  custom_entity:stop_movement()
  alt_movement = false
  object = nil
end

--ACTIVATES WHEN THE CUSTOM_ENTITY RUNS INTO A "JUMPER"
function jumper_found()
    --ENDS ANY MOVEMENT
    end_movement()

    --ASSIGNS THE ENCOUNTERED "JUMPER" SO I CAN PULL PROPERTIES FROM IT
    object = custom_entity:get_facing_entity()

    --CREATES THE JUMP MOVEMENT
    jump = sol.movement.create("jump")

    jump:set_ignore_obstacles(true)

    --PULLS A CUSTOM "DIR" PROPERTY WHICH TELLS THE CUSTOM ENTITY WHICH WAY TO JUMP
    jump:set_direction8(object:get_property("dir"))

    --PULLS A CUSTOM "DIST" PROPERTY WHICH TELLS THE CUSTOM ENTITY HOW FAR TO JUMP
    jump:set_distance(object:get_property("dist"))

    --STARTS THE JUMP AND ENDS THE JUMP SO STANDARD MOVEMENT CAN RESUME
    jump:start(custom_entity, end_movement)
   
    --CUSTOM VARIABLE USED ELSEWHERE TO PREVENT STANDARD MOVEMENTS FROM ACTIVATING WHILE JUMPING
    alt_movement = true
end

--RUNTIME MONITORING
function custom_entity:on_update()

  print(object)

end

The problem is that "get_facing_entity()" will only work on the first entity it encounters.  For instance, I have a "chest" entity and a "jumper" entity; if I bump the custom entity into the "jumper," then "get_facing_entity()" assigns that entity to "object."  I can manually set "object" back to "nil" using a debug key command, but if I proceed to bump the custom entity into the "chest," then "get_facing_entity()" still returns the id of the "jumper" that it touched earlier, and the "jump" movement will activate.

What's even more strange is if I bump into the "chest" first, then the "chest" entity is assigned to "object" even though according to my understanding of the above code, my custom "jumper_found()" function should only be activating when the custom entity explicitly encounters a "jumper" entity.

I've moved my "jumper_found()" function declaration into the "on_created()" function to ensure it doesn't run unless called.  No change.

I've attempted making "object" local.  No change.

I've attempted embedding "get_facing_entity()" into the "on_update()" function so it constantly runs.  No change.

I'm sure I am probably just using "get_facing_entity()" wrong, but I've been stumped for 3 days now on this one task.

Pages: [1]