Page 272 of 396

Re: Ask a simple question, get a simple answer

Posted: Tue Dec 11, 2018 9:50 pm
by Isaac
AFAIK there is not... not within the running game; but there might be a way to capture the entire output of the console in a terminal/command prompt. Minmay could say... I've never been able to manage it.

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 19, 2018 10:47 pm
by Zo Kath Ra
Isaac wrote: Tue Dec 11, 2018 9:50 pm AFAIK there is not... not within the running game; but there might be a way to capture the entire output of the console in a terminal/command prompt. Minmay could say... I've never been able to manage it.
Now that you mention it...
viewtopic.php?f=22&t=10478

Re: Ask a simple question, get a simple answer

Posted: Sun Dec 23, 2018 4:02 pm
by Zo Kath Ra

Code: Select all

var = 1

res = iff(var ~= nil, 1 + var, var)

print(res)
This code works, but if I change var to nil, I get the error:
attempt to perform arithmetic on global 'var' (a nil value)

Is this a bug in iff() or am I doing something wrong?

If it's a bug, I'll just have to use
res = (var ~= nil) and (1 + var) or var

Re: Ask a simple question, get a simple answer

Posted: Sun Dec 23, 2018 7:13 pm
by minmay
That error happens before iff() is called. You are trying to evaluate "1 + var" while var is nil, so you get that error.

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 26, 2018 7:36 pm
by 7Soul
Is it possible to add a certain hook to every item? For example, adding onEquipItem to every armor at once, instead of having to redefine every single Armor item and adding onEquipItem to each one

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 26, 2018 8:26 pm
by Isaac
Not that I am aware of; but it is possible to use a script/loop to read and then redefine multiple items. I assume that the framework mod/script for Grimrock does just that—though I've not used, or looked at it much myself.

Re: Ask a simple question, get a simple answer

Posted: Thu Dec 27, 2018 1:05 am
by Zo Kath Ra
Isaac wrote: Wed Dec 26, 2018 8:26 pm Not that I am aware of; but it is possible to use a script/loop to read and then redefine multiple items. I assume that the framework mod/script for Grimrock does just that—though I've not used, or looked at it much myself.
Why can't you just add the hook to base_item ?
I tried it some time ago, and it didn't work, but I don't know why.

Re: Ask a simple question, get a simple answer

Posted: Thu Dec 27, 2018 2:39 am
by minmay
Overwrite defineObject with your own version that adds the hook, like this:

Code: Select all

local orig_defineObject = defineObject
local onEquipItemHook = function(self, champion, slot)
	print("asdfasdf")
end
defineObject = function(def)
	if def.components then
		for _,c in pairs(def.components) do
			if c.class == "EquipmentItem" then
				c.onEquipItem = equipItemHook
			end
		end
	end
	orig_defineObject(def)
end

Re: Ask a simple question, get a simple answer

Posted: Thu Dec 27, 2018 4:55 am
by Isaac
Zo Kath Ra wrote: Thu Dec 27, 2018 1:05 am Why can't you just add the hook to base_item ?
I tried it some time ago, and it didn't work, but I don't know why.
I've not tried that myself either, but offhand I think it would break some (or all?) special case magical items, unless —as minmay lists above— you redefine their components intact, but with the added hook feature. Item definitions will take the base_item and redefine the item component to suit... overwriting any previous item component (and possibly others).

Re: Ask a simple question, get a simple answer

Posted: Thu Dec 27, 2018 6:10 am
by 7Soul
minmay wrote: Thu Dec 27, 2018 2:39 am Overwrite defineObject with your own version that adds the hook, like this:

Code: Select all

local orig_defineObject = defineObject
local onEquipItemHook = function(self, champion, slot)
	print("asdfasdf")
end
defineObject = function(def)
	if def.components then
		for _,c in pairs(def.components) do
			if c.class == "EquipmentItem" then
				c.onEquipItem = equipItemHook
			end
		end
	end
	orig_defineObject(def)
end
It works, thanks!
(You misspelled the second onEquipItemHook btw)
And worth pointing out this should be put after standard assets and before mod assets


Let me use this opportunity to ask something else...
Is it possible to do some kind of "is in game" check? I have class traits that use variables that are set in the map so they crash the game in the character creation screen...

EDIT: actually, I can just check if the script object exists :) Nvm then!