ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Tue Dec 18, 2018 10:04 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Sep 19, 2015 9:37 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
I am trying to get the player to rest as part of a larger action (specifically I'm trying to make a player AI). I clearly don't understand the resting pathway in the code. Actual question: How do you initiate player resting from the code?

So far I found engine.interface.PlayerRest, which seems to be what I want. However, if I call PlayerRest.initRest() it calls PlayerRest.checkRest(), which is defined as:
Code:
function _M:restCheck()
   return false, "player:restCheck() method not defined"
end

Which is clearly wrong (and provides a misleading error message). I am in the process of trying to superload it with a call to mod.class.Player:restCheck(), but I can't seem to effect PlayerRest at all. Is it impossible to superload/overload engine files?

Actual question: How do you initiate player resting from the code?

If it helps, here is the current contents of my superload/engine/interface/PlayerRest.lua:
Code:
local Player = require "mod.class.Player"

local _M = loadPrevious(...)

function _M:restCheck()
    game.log("#RED#overload functional") -- Just so I can see an effect in the console
   return Player.restCheck()
end

return _M

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
PostPosted: Sat Sep 19, 2015 11:28 pm 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5780
The game initiates resting via: self.player:restInit(), which means call restInit on the player.
PlayerRest.initRest() calls initRest on nothing, which since it doesn't have any resting conditions defined on it, doesn't work.

Also: Hooray you got the right forum this time! :D

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Mon Sep 21, 2015 8:45 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
Thanks! So if I'm doing this from inside the Player.lua file, do I call _M:restInit()? I tried that, and it gave me an error that ActorTalents.getTalentLevelRaw() indexed a nil "talents" value.

And yeah, I was having trouble seeing the different forum categories. I didn't realize the version separation existed, and I hadn't found the definition of module vs addon yet.

EDIT: Upon further consideration, I may be putting my player AI functions in the wrong file. I really want the instantiation of the player object to work with, and the stuff it calls to tie into the game, not the player class. Of course, this whole experience has been learning how ToME works internally from scratch, so discovering that my very first step was wrong is pretty unsurprising.

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 1:09 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5780
Assuming you want the player to rest, you need to call <the player actor entity>:initRest().
Calling _M:initRest() inside Player.lua is like telling the file to rest.
The player entity can be referenced from anywhere via 'game.player', but it is also frequently 'self'.

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 1:27 am 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
Huh, I thought I tried that, but apparently not.

Thanks again. For some reason "self" isn't defined in my superload of Player.lua, but calling it from game.player works.

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 1:49 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5780
Self is always defined.
Calling a function via : eg. game.player:initRest() means that 'self' inside initRest() is game.player.

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 3:19 am 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
I have an order of execution problem now. I call restInit with
Code:
game.player:restInit(nil,nil,nil,nil,player_ai_after_rest())
which *should* call my player_ai_after_rest() function AFTER the rest has ended, but it turns out not to? I have it printing out log messages, and the log from my after function prints BEFORE the console message "Resting starts...".

How can I check to make sure resting has finished before I execute without blocking or making an infinite loop?

EDIT: Response about "self" stuff: Apparently not, because if i use "self" in my superload/Player.lua directly it gives the error "attempt to index the global value 'self' (a nil value)". Calling things with the colon obviously sets the self value for those function executions, but my local functions don't seem to have a self. It's probably because they're local functions and not _M:functions.

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 8:53 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5780
Remove the () from player_ai_after_rest(). You want to pass the function, not call it.

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 7:26 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
XD XD XD I CAN'T BELIEVE I DID THAT. NOTHING TO SEE HERE NOT A BASIC SYNTAX ERROR OR ANYTHING.

Strange execution bug explained by stupidity. Just. Wow.

_________________
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group