[Solved] Bug with "get_facing_entity" ?

Started by SyF, March 13, 2017, 11:38:57 AM

Previous topic - Next topic
March 13, 2017, 11:38:57 AM Last Edit: March 14, 2017, 10:03:14 AM by SyF
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) Select

local item = ...
local game = item:get_game()
---------------------------------------
function item:on_created()
  self:set_savegame_variable("slim_stick")
  self:set_assignable(true)
end
---------------------------------------
function item:on_obtaining()
  game:set_item_assigned(1,self)
end
---------------------------------------
local function enabled_custom(name_ent) --Timer on custom entity
  local map = item:get_map()
  local custo_ent = map:get_entity(name_ent)
  sol.timer.start(5000, function()
    custo_ent:set_enabled(false)
    end)
end
---------------------------------------
function item:on_using()
local map = item:get_map()
local hero = map:get_hero()

-- Coordinates Hero
  local hero_x, hero_y, hero_layer = hero:get_position()
  local direction = hero:get_direction()

-- Slim position
  local slim_x, slim_y

if direction == 0 then
    slim_x = hero_x + 24
    slim_y = hero_y
  elseif direction == 1 then
    slim_x = hero_x
    slim_y = hero_y - 24
  elseif direction == 2 then
    slim_x = hero_x - 24
    slim_y = hero_y
  elseif direction == 3 then
    slim_x = hero_x
    slim_y = hero_y  + 24
  end

-- Slim creation
local tai_hitbox = 48
spot_slim = map:create_custom_entity{
    name = "slim",
    layer = hero_layer,
    x = slim_x,
    y = slim_y,
    width = tai_hitbox,
    height = tai_hitbox,
    direction = direction,
    sprite = "entities/spot_slim"
    }

-- Bigger hitbox
spot_slim:set_origin(tai_hitbox/2, tai_hitbox/2)

-- Ground modification
spot_slim:set_modified_ground("traversable")

-- Test to determinate the type of the ground in front of the hero
local ground_entity = hero:get_facing_entity()
  print(ground_entity)

-- End of the function
local name_slim = spot_slim:get_name()
  item:set_finished()
enabled_custom(name_slim)
end


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.

Okay, thanks !

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

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