ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Tue Nov 21, 2017 1:33 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Jul 22, 2015 8:34 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
I made the following simplistic load hook:

Code:
local KeyBind = require "engine.KeyBind"
local Player = require "mod.class.Player"

class:bindHook("ToME:run", function(self, data)
   KeyBind:load("toggle-player-ai")
   game.key:addBinds {
      TOGGLE_PLAYER_AI = function()
          game.log("#GOLD#Player AI Toggle requested!")
         game.log("#GOLD#Player AI is: %s", Player:ai_active and "#LIGHT_GREEN#enabled" or "#LIGHT_RED#disabled")
         Player:player_ai_start()
      end
   }
end)


If I don't comment out the "require Player" line, the mod crashes between character selection and loading the first level. It gets to 100% and then just doesn't start the game. I have otherwise tested the mod and I can get the keybind to toggle a local boolean, but I'd like to have access to the Player class so I can activate a sort of "autoexplore"-like function.

The Player:ai_active boolean and the Player:player_ai_start() functions are things I added in a superload. Is that confusing the load order and trying to parse functions that don't exist yet? How can I work around that?

I can post the superload/mod/class/Player.lua too if that's relevant.

_________________
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: Thu Jul 23, 2015 8:15 am 
Offline
Spiderkin

Joined: Sat Feb 11, 2012 1:12 am
Posts: 543
If you look in the te4_log.txt file in the same directory as your executable, you should see a detailed crash reason at the end. If none shows up/the log is incomplete, try loading ToME with the --flush-stdout argument.


Top
 Profile  
 
PostPosted: Fri Jul 24, 2015 1:43 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5514
Probably an error in your superload.

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


Top
 Profile  
 
PostPosted: Fri Jul 24, 2015 4:35 am 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
I found this error:

Code:
Lua Error: /mod/class/Actor.lua:258: table index is nil
   At [C]:-1 __newindex
   At /mod/class/Actor.lua:258 init
   At /mod/class/Player.lua:84 init
   At /engine/class.lua:104 new
   At /mod/class/Game.lua:192 newGame
   At /mod/class/Game.lua:136 runReal
   At /mod/class/Game.lua:93 run
   At /engine/Module.lua:990 instanciate
   At /engine/utils.lua:2197 showMainMenu
   At /engine/init.lua:162
   At [C]:-1 dofile
   At /loader/init.lua:204


I then tried to add a require for Actor, which added this error (without resolving the above one):

Code:
Lua Error: /mod/class/Game.lua:2206: attempt to index field 'player' (a nil value)
   At [C]:-1 __index
   At /mod/class/Game.lua:2206


Any idea what's going wrong?

_________________
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: Fri Jul 24, 2015 10:15 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5514
At a guess, your require Player line in load.lua is causing Player to initialise too early.
Try moving it into the function where you need it.

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


Top
 Profile  
 
PostPosted: Fri Jul 24, 2015 9:10 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
Thanks! I was trying to treat "require" like "include" from C, never would have thought of putting it in a function. Now it's actually running and giving me errors when I try to run the function (function is nil), which I assume is because I didn't define it right.

It tells me that the player_ai_start function is nil, so I need to figure out how to define/call it properly. I tried calling it with Player:player_ai_start() and Player.player_ai_start() to no avail. I tried defining the function as function _M:player_ai_start() and function player_ai_start() without effect.

Disclaimer: I've never used Lua before, so help with the basic syntax may be required.

EDIT: I now know that the colon is for function declaration and it adds a self argument, so I should really be calling things with dot. This hasn't solved my problem, but it has made me less dumb.

_________________
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: Thu Sep 17, 2015 9:07 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 56
It was an even stupider error. I forgot to add
Code:
superload = true
to my init.lua file.

Issue is now resolved.

_________________
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  [ 7 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