-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Program registration #47
Comments
While in theory it should work, I honestly recommend to you to calculate the yaw and pass it to |
But assuming I want to rotate to a place that will change in a previous instruction or program. How do I do this? |
The problem is in
|
Ah got it, yes, that happens. npc.programs.instr.register("future_rotate", function(self, args)
local future_pos = npc.exec.var.get(self, "future_pos")
npc.programs.instr.execute(self, "advanced_npc:rotate", {yaw = minetest.dir_to_yaw(vector.direction(self.object:getpos(), future_pos))})
end Then enqueue this instruction after the execution of the program/instruction that calculates and stores the pos. |
So if I want to reference my future pos I should do. npc.programs.instr.register("update_my_pos", function(self, args)
npc.exec.var.set(self, "future_pos", self.object:getpos())
end
npc.programs.instr.register("rotate", function(self, args)
local future_pos = npc.exec.var.get(self, "future_pos")
npc.programs.instr.execute(self, "advanced_npc:rotate", {yaw = minetest.dir_to_yaw(vector.direction(self.object:getpos(), future_pos))})
end
npc.programs.register("interact", function(self, args)
local tempo = args.time or 5
local pos = npc.programs.helper.get_pos_argument(self, args.pos, true)
-- Rotate
npc.exec.proc.enqueue(self, "rotate", {})
-- Wait
npc.exec.proc.enqueue(self, "wait", {
time = time,
})
-- Walk to a random pos
npc.exec.proc.enqueue(self, "walk_to_pos", {})
-- Update variable
npc.exec.proc.enqueue(self, "update_my_pos", {})
-- New Rotate
npc.exec.proc.enqueue(self, "advanced_npc:rotate", {})
end) |
My example sucks, but I want to say that the variable needs to be updated by another instruction. |
Maybe if you tell me your exact use case I can help you figure out how to do it. But in general yes your code should work. |
I'm trying to create a program and get this for now.
It looks like the NPC does not rotate to the right place.
I did not understand correctly where the temporary data is and how to reference future places.
The text was updated successfully, but these errors were encountered: