Skip to content
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

Open
BrunoMine opened this issue Apr 27, 2018 · 7 comments
Open

Program registration #47

BrunoMine opened this issue Apr 27, 2018 · 7 comments

Comments

@BrunoMine
Copy link
Contributor

BrunoMine commented Apr 27, 2018

I'm trying to create a program and get this for now.

npc.programs.register("sunos:interagir", 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, "advanced_npc:rotate", {
		start_pos = self.object:getpos(),
		end_pos = pos,
	})
	
	-- Wait
	npc.exec.proc.enqueue(self, "advanced_npc:wait", {
		time = time,
	})
end)

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.

@hkzorman
Copy link
Owner

While in theory it should work, I honestly recommend to you to calculate the yaw and pass it to advanced_npc:rotate as yaw argument.
Also, see if pos has the position argument that you expect.

@BrunoMine
Copy link
Contributor Author

But assuming I want to rotate to a place that will change in a previous instruction or program. How do I do this?

@BrunoMine
Copy link
Contributor Author

The problem is in npc.programs.helper.get_pos_argument 3rd argument, true is for acess_node.
I must have mistaken myself for the comments.

-- Return the first position only if it couldn't find an owned
-- place, or if it there is only one
if use_access_node == true then
    return places_pos[1].access_node, places_pos[1].pos
else
    return places_pos[1].pos
end

@hkzorman
Copy link
Owner

hkzorman commented Apr 27, 2018

Ah got it, yes, that happens.
Regarding the future position, that is a little bit more tricky. That's the purpose of variables, store the position as variable (npc.exec.var.put()). Register a instruction that does this:

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.

@BrunoMine
Copy link
Contributor Author

BrunoMine commented Apr 27, 2018

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)

@BrunoMine
Copy link
Contributor Author

My example sucks, but I want to say that the variable needs to be updated by another instruction.

@hkzorman
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants