Following a tutorial: Custom entity Won't Spawn (new to the api)

Post Reply
ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

local object = minetest.get_player_by_name("singleplayer")
local pos = object:get_pos()
object:set_pos({x = pos.x, y = pos.y + 1, z = pos.z})
object:move_to({x = pos.x, y = pos.y + 1, z = pos.z})
object:set_properties({
visual = "mesh",
mesh = "entity.b3d",
textures = {"character_copy.png"},
visual_size = {x = 1, y = 1},
})
local MyEntity = {
initial_properties = {
hp_max = 1,
physical = true,
collied_with_objects = false,
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
visual = "wielditem",
visual_size = {x = 0.4, y = 0.4},
textures = {""},
sprietdiv = {x = 1, y = 1},
initial_sprite_properties = {x = 0, y = 0},
},
message = "Deffaultmeesage"
}
function MyEntity:set_message(msg)
self.message = msg
end
function MyEntity:on_step(dtime)
local entity = object:get_luaentity()
local object = entity.object
local pos = self.object:get_pos()
local pos_down = vector.subtract(pos, vector.new(0,1,0))
local delta
if minetest.get_node(pos_down).name == "air" then
delta = vector.new(0,-1, 0)
elseif minetest.get_node(pos).name == "air" then
delta = vector.new(0,0,1)
else
delta = vector.new(0,1,0)
end
delta = vector.multiply(delta, dtime)
self.object:move_to(vector.add(pos,delta))
end
function MyEntity:on_punch(hitter)
minetest.chat_send_player(hitter:get_player_name(), self.message)
end
function MyEntity:get_staticdata()
return minetest.write_json({
message = self.message,
})
end
function MyEntity:on_activate(staticdata, dtime_s)
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.parse_json(staticdata) or {}
self:self_message(data_message)
end
local pos ={x =1, y =2, z = 3}
local obj = minetest.add_entity(pos,"intelli_ai:entity", nil)
obj:get_luaentity("intelli_ai:entity"):set_message("hello!")
print("entity is at" ..minetest.pos_to_string(object:get_pos()))
minetest.register_entity("intelli_ai:entity", MyEntity)
end

ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

I think it's something to with staticdata to somehow naming the entity? I literally just followed a tutorial.

ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

I've been focusing on this for hours (I will back to this forum in 15 minutes)... If someone could help with this it would be greatly appreciated...
Last edited by ChedderMonger on Sat Aug 13, 2022 21:25, edited 1 time in total.

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by jwmhjwmh » Post

I think the problem is that you call minetest.add_entity inside on_activate. Since minetest.add_entity calls on_activate again, the code never finishes running.

There seem to be other issues with the code, but you can probably fix them once you fix this first bug.

ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

AsyncErr: Lua: Runtime error from mod 'intelli_ai' in callback environment_Step(): ...er\minetest-5.6.0-win64\bin\..\builtin\common\vector.lua:212: attempt to index local 'a' (a nil value)
stack traceback:

I think this is good news because then it's a time consitency problem

ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

I'm starting a an easier project once my code is ready to move on.... I love your slugs mod

ChedderMonger
New member
Posts: 7
Joined: Sun Aug 07, 2022 18:02
In-game: Cheddar

Re: Following a tutorial: Custom entity Won't Spawn (new to the api)

by ChedderMonger » Post

I followed this from rubenwardy.com Objects, Players, and Entities

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests