Ask a simple question, get a simple answer
Re: Ask a simple question, get a simple answer
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.
- Zo Kath Ra
- Posts: 937
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
- Zo Kath Ra
- Posts: 937
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
Code: Select all
var = 1
res = iff(var ~= nil, 1 + var, var)
print(res)
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
That error happens before iff() is called. You are trying to evaluate "1 + var" while var is nil, so you get that error.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
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
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.
- Zo Kath Ra
- Posts: 937
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
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
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
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
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).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.
Re: Ask a simple question, get a simple answer
It works, thanks!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
(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!