Page 1 of 1

Newbie Dev Question

Posted: Wed Mar 06, 2019 10:11 pm
by smithfield
I'm taking my standard baby steps w/ a new environment.

Inside of the context of my own addon

I want to cause the change of one line in LevelUpDialog.lua

from this

Code: Select all

 Dialog.init(self, "Levelup: "..actor.name, game.w * 0.9, game.h * 0.9, game.w * 0.05, game.h * 0.05)
to this

Code: Select all

 Dialog.init(self, "Levelup: "..actor.name.." (lvl: "..actor.level..")", game.w * 0.9, game.h * 0.9, game.w * 0.05, game.h * 0.05)
It seems that there are several ways to achieve this result.

What do you recommend?

Copy the whole file, change one line and overload it?

I'm trying to get into the right frame of mind about this stuff from the outset.

Re: Newbie Dev Question

Posted: Wed Mar 06, 2019 11:54 pm
by HousePet
I don't recall ever trying to change a dialog function.
What I would normally try to do with any function inside the Mod folder I wanted to change is to find where it is in the in game data structure and overwrite it with the addon's Load hook. In this case, just the init function.
However, I don't know how to find that dialog in the data structure. Its not under mod.dialogs, where I would expect it.

Re: Newbie Dev Question

Posted: Thu Mar 07, 2019 12:46 am
by Doctornull
That line appears in the middle of a big function.

You can superload to just overwrite that function, but it's pretty big.

Here's how I overloaded one function in that dialog in Nulltweaks:

Code: Select all

-- tome-nulltweaks/superload/mod/dialogs/LevelupDialog.lua

local _M = loadPrevious(...)

_M.isUnlearnable = function(self, t, limit)
   if not self.actor.last_learnt_talents then return end
   if self.on_birth and self.actor:knowTalent(t.id) and not t.no_unlearn_last then return 1 end -- On birth we can reset any talents except a very few
   local list = self.actor.last_learnt_talents[t.generic and "generic" or "class"]
   local max = self.actor:lastLearntTalentsMax(t.generic and "generic" or "class")
   local min = 1
   if limit then min = math.max(1, #list - (max - 1)) end

   local seen = 0
   -- Check for visible monsters, only see LOS actors, so telepathy wont prevent it
   if game and game.level and game.level.entities then
      for k, v in pairs(game.level.entities) do
	 if v.__CLASSNAME and (v.__CLASSNAME == "mod.class.NPC") and (game.player:reactionToward(v) < 0) and (v.hasEffect and not v:hasEffect(v.EFF_VAULTED)) then
	    seen = seen + 1
	 end
      end
   end

   for i = #list, min, -1 do
      if list[i] == t.id then
	 if not game.state.birth.force_town_respec or (seen <= 0) or (game.level and game.level.data and game.level.data.allow_respec == "limited")
	 then
	    return i
	 else
	    return nil, i
	 end
      end
   end
   return nil
end

return _M



On the upside, here's the code in 1.6 git right now:

Code: Select all

	Dialog.init(self, "Levelup: "..actor.name..", level "..actor.level, game.w * 0.9, game.h * 0.9, game.w * 0.05, game.h * 0.05)
So basically what you want to happen is already going to happen, eventually.

Re: Newbie Dev Question

Posted: Thu Mar 07, 2019 8:54 am
by smithfield
So basically what you want to happen is already going to happen, eventually.
Yes. But with your help, eventually is right now for me.
Thanks got me over a big hump.
I'm not sure that this thing can be done w/ an overload - that's what I tried first and I couldn't even cause bugs.
Superload for the win.

HousePet said:
find where it is in the in game data structure
I think I know the answer to this, but it would help so much to hear it said.

How do you go about examining the object structure?
Which tool do you open?
Do you work inside the game in the Dev mode? (i haven't even tried this yet)
What is the sequence of commands that you would give to see the list of mod.dialogs appear?

A specific example like this lights up things for miles around.

Re: Newbie Dev Question

Posted: Thu Mar 07, 2019 11:04 pm
by HousePet
Superload will do it, but its not great for a few obscure reasons.

To see the in game data structure, open the game, enable developer mode, load any character, and press Alt+L (or whatever) to open the Lua console.
From there try typing in '=mod.dialogs' (if I remember correctly).
I don't think there is a full list of the base objects anywhere, but you can press tab to get an auto complete list of options. So type = and then press tab and it should show you the full base directory.
I am not aware of a way of searching in that though, so it helps if you have some idea of how the engine has loaded all the different components. My quick search in the game files couldn't find where the LevelupDialog.lua file was even called from. :|