Author Topic: [Solved] Bug with "get_facing_entity" ?  (Read 390 times)

SyF

  • Newbie
  • *
  • Posts: 13
    • View Profile
[Solved] Bug with "get_facing_entity" ?
« on: March 13, 2017, 11:38:57 am »
Hi,
I'm on th version 1.5.2 and I create an item to allow the hero to walk on specific grounds (spikes, lava...). I managed to create a custom entity and the hero can walk on it.
Now I just want the entity to be created only on there specific grounds.
I use the function "get_facing_entity" (lign 66) to get the entity in front of the hero and my variable got the delicious name "0x063b4a08" (or something like that).

Do you know if it is a bug or not ?

My code:
Code: Lua
  1. local item = ...
  2. local game = item:get_game()
  3. ---------------------------------------
  4. function item:on_created()
  5.   self:set_savegame_variable("slim_stick")
  6.   self:set_assignable(true)
  7. end
  8. ---------------------------------------
  9. function item:on_obtaining()
  10.   game:set_item_assigned(1,self)
  11. end
  12. ---------------------------------------
  13. local function enabled_custom(name_ent) --Timer on custom entity
  14.   local map = item:get_map()
  15.   local custo_ent = map:get_entity(name_ent)
  16.   sol.timer.start(5000, function()
  17.     custo_ent:set_enabled(false)
  18.     end)
  19. end
  20. ---------------------------------------
  21. function item:on_using()
  22. local map = item:get_map()
  23. local hero = map:get_hero()
  24.  
  25. -- Coordinates Hero
  26.   local hero_x, hero_y, hero_layer = hero:get_position()
  27.   local direction = hero:get_direction()
  28.  
  29. -- Slim position
  30.   local slim_x, slim_y
  31.  
  32. if direction == 0 then
  33.     slim_x = hero_x + 24
  34.     slim_y = hero_y
  35.   elseif direction == 1 then
  36.     slim_x = hero_x
  37.     slim_y = hero_y - 24
  38.   elseif direction == 2 then
  39.     slim_x = hero_x - 24
  40.     slim_y = hero_y
  41.   elseif direction == 3 then
  42.     slim_x = hero_x
  43.     slim_y = hero_y  + 24
  44.   end
  45.  
  46. -- Slim creation
  47. local tai_hitbox = 48
  48. spot_slim = map:create_custom_entity{
  49.     name = "slim",
  50.     layer = hero_layer,
  51.     x = slim_x,
  52.     y = slim_y,
  53.     width = tai_hitbox,
  54.     height = tai_hitbox,
  55.     direction = direction,
  56.     sprite = "entities/spot_slim"
  57.     }
  58.  
  59. -- Bigger hitbox
  60. spot_slim:set_origin(tai_hitbox/2, tai_hitbox/2)
  61.  
  62. -- Ground modification
  63. spot_slim:set_modified_ground("traversable")
  64.  
  65. -- Test to determinate the type of the ground in front of the hero
  66. local ground_entity = hero:get_facing_entity()
  67.   print(ground_entity)
  68.  
  69. -- End of the function
  70. local name_slim = spot_slim:get_name()
  71.   item:set_finished()
  72. enabled_custom(name_slim)
  73. end
  74.  
« Last Edit: March 14, 2017, 10:03:14 am by SyF »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1041
    • View Profile
Re: Bug with "get_facing_entity" ?
« Reply #1 on: March 13, 2017, 11:42:23 am »
print(entity) only prints the internal address of the object, like when you do print(t) for a table t, for example.
Try print(entity:get_type()) or print(entity:get_name()) to have more helpful info.

SyF

  • Newbie
  • *
  • Posts: 13
    • View Profile
[Solved] Bug with "get_facing_entity" ?
« Reply #2 on: March 14, 2017, 10:02:50 am »
Okay, thanks !

And, for my test, I just use a "get_ground" to get the type of ground  ;)

MetalZelda

  • Hero Member
  • *****
  • Posts: 504
    • View Profile
Re: [Solved] Bug with "get_facing_entity" ?
« Reply #3 on: April 08, 2017, 12:04:05 am »
get_facing_entity() will return the entity in front of the hero, not the ground

You should use map:get_ground() with as base, slim_x, y variable