Nextbot Problems (attempt to yield across C-call boundary)
6 replies, posted
https://pastebin.com/fmdPdxwk
So, I'm doing something pretty weird with Nextbot. I'm trying to make a library of "schedules" so to speak so that I can call them later on in other parts of the script.
For instance, the way I get this npc to do the walk animation would be to do:
entity:updateAction("walk", Vector(0, 0, 0)
someplace else in the script. But when I do that, I seem to get this error:
[ERROR] gamemodes/base/entities/entities/base_nextbot/sv_nextbot.lua:328: attempt to yield across C-call boundary
1. yield - [C]:-1
2. MoveToPos - gamemodes/base/entities/entities/base_nextbot/sv_nextbot.lua:328
3. doWalk - gamemodes/swagadventures/entities/entities/nextbot_npc.lua:33
4. updateAction - gamemodes/swagadventures/entities/entities/nextbot_npc.lua:22
5. unknown - gamemodes/swagadventures/init.lua:46
6. unknown - lua/includes/modules/concommand.lua:54
Any idea?
You can't run MoveToPos anywhere you like, it has to be in the RunBehaviour hook. Thus you want to store the go-to pos in some variable on the entity then use that in the RunBehaviour hook like:
function ENT:RunBehaviour()
while true do
if self.scheduledWalk then
self:MoveToPos(self.scheduledWalk)
self.scheduledWalk = nil -- Reset so it doesn't get called multiple times
end
end
end
function ENT:DoWalk(pos)
self.scheduledWalk = pos
end
If you're expecting multiple walk calls before one is finished you might want to store them in a table or something so they get called sequentially. That's up to you.
Yeah that ended up working. MoveToPos doesn’t stop until it gets to where you tell it to go. Is there a way to stop it before it ends if I give it a new location mid-walking?
MoveToPos is a lua function so your best bet is copying its source garrysmod/sv_nextbot.lua at master · Facepunch/garrysmod · GitHu.. to your entity and then add some check in the loop there to quit it prematurely.
It seems that MoveToPos runs on a while loop and until the path is complete (the while loop ends), nothing can get updated. I wonder how you'd disrupt a while loop with a changed variable.
You can just call break in it once your condition is met.
I gave up on Nextbot, it sucks and it sucks even more that some things on the base_ai are broken because of it. But, thanks anyways!
Sorry, you need to Log In to post a reply to this thread.