Page 1 of 1
Looping around extended player actions
Posted: Tue Sep 22, 2015 9:10 pm
by Charidan
I'm trying to make an AI that runs the player. I want it to be able to cause the player to take consecutive actions. The problem is that if I just try to write a loop, the game never updates the turn and so I just block execution.
What do I need to overwrite/hook/check to make sure that a move I have entered is executed fully, or alternately what do I check to make sure the game is waiting for player input? Ideally there is a function called when the game waits for player input that I can hook/superload to call my AI functions.
Re: Looping around extended player actions
Posted: Tue Sep 22, 2015 10:01 pm
by Radon26
Here goes stupid idea coming from someone who never coded anything in this game:
have you tried to make it skip a turn and then, if condition still isn't met, repeat, and if it is, stop?
Re: Looping around extended player actions
Posted: Tue Sep 22, 2015 10:58 pm
by HousePet
No idea on this one.
Re: Looping around extended player actions
Posted: Tue Sep 22, 2015 11:28 pm
by grayswandir
You probably need to take a look at Player's :act function, as that's what waits for user input, I believe. So, like, you put a wrapper around it that, if a flag is set, calls the npc act function with a given ai (somehow) instead of the player one.
Re: Looping around extended player actions
Posted: Wed Sep 23, 2015 10:02 pm
by Charidan
Thanks guys. My current setup is to superload Player:act() and then check the game.pause flag (and my ai flag) like so:
Code: Select all
local old_act = _M.act
function _M:act()
old_act(game.player)
if (not game.pause) and _M.ai_active then
player_ai_act()
end
end
And it's mostly working. For some reason now, every time I try to rest from the AI it gives me an error that a dialog is up so it can't rest. This is partially true, because the "You are resting..." dialog is open, except that shouldn't stop resting. If I can clean that up so the AI can rest again, I'll have a fully-functional (basic) AI that rests, auto explores, and walks into enemies it can see.
EDIT UPDATE: I added "and not game.player.resting" to the condition, and it still SAYS resting stopped because of dialog, but it seems to rest properly anyways. However, I have now learned that hotkeys don't work while the AI is active because of how I interact with the act() function, so I can't stop the AI once it's on, and it starts autoexploring back and forth between the level entrance and exit. Progress!