Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post 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
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post 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
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post 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.
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.
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post 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
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post 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.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post 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
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.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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).
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post 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!
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
Post Reply