[SOLVED] multiple clickable component

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

Re: [SOLVED] multiple clickable component

Post by minmay »

Isaac wrote:Even before, the player was not able to pick up any 'removed' items, so it doesn't seem to matter for limited [special case] use.
If they pick up the item in the surface that it was "moved" to, that's what can cause a crash after save/load.
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: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: [SOLVED] multiple clickable component

Post by Isaac »

minmay wrote:
Isaac wrote:Even before, the player was not able to pick up any 'removed' items, so it doesn't seem to matter for limited [special case] use.
If they pick up the item in the surface that it was "moved" to, that's what can cause a crash after save/load.
Either not having it accessible at all [off map], or not having a clickable component on the object... but it does not seem possible to actually pick up the [invisible] object from the original surface. If the surface is empty, it can be destroyed, (anything with a game object in the surface must be destroyed first, or it gets left behind, and the game halts if they click on the items when it tries to check if it's possible to reach the object.)

I think it would be easy to write a function that tallies the contained items, removes the intended target (being moved) from it's stored table, and destroys the alcove; replacing it with one that has the original contents from the stored table, sans the moved item.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [SOLVED] multiple clickable component

Post by minmay »

Isaac wrote:
minmay wrote:
Isaac wrote:Even before, the player was not able to pick up any 'removed' items, so it doesn't seem to matter for limited [special case] use.
If they pick up the item in the surface that it was "moved" to, that's what can cause a crash after save/load.
Either not having it accessible at all [off map], or not having a clickable component on the object... but it does not seem possible to actually pick up the [invisible] object from the original surface. If the surface is empty, it can be destroyed, (anything with a game object in the surface must be destroyed first, or it gets left behind, and the game halts if they click on the items when it tries to check if it's possible to reach the object.)
Yes, you can't pick it up from the original surface because the OBJECT is moved to the other surface. The ITEM COMPONENT is still REFERENCED by BOTH. SURFACES. So when you pick up the item from one surface, the object is removed from the map, but the other surface STILL HAS A REFERENCE TO IT.
Isaac wrote:I think it would be easy to write a function that tallies the contained items, removes the intended target (being moved) from it's stored table, and destroys the alcove; replacing it with one that has the original contents from the stored table, sans the moved item.
Yes, you can do it by destroying SurfaceComponents, this is like the very first thing I mentioned...
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: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: [SOLVED] multiple clickable component

Post by Isaac »

minmay wrote:So when you pick up the item from one surface, the object is removed from the map, but the other surface STILL HAS A REFERENCE TO IT.
Isaac wrote:I think it would be easy to write a function that tallies the contained items, removes the intended target (being moved) from it's stored table, and destroys the alcove; replacing it with one that has the original contents from the stored table, sans the moved item.
Yes, you can do it by destroying SurfaceComponents, this is like the very first thing I mentioned...
Both of these are obvious. :?
Are you reading my posts as some sort of one-up-manship?
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: [SOLVED] multiple clickable component

Post by Zo Kath Ra »

Isaac wrote:*We should request a champion:dropItem() function the next time Petri offers a Glögg session; dropMouseItem() would be useful too.
How do you script a dropMouseItem() function?
I need one for a keyring I'm working on.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: [SOLVED] multiple clickable component

Post by Isaac »

Zo Kath Ra wrote:
Isaac wrote:*We should request a champion:dropItem() function the next time Petri offers a Glögg session; dropMouseItem() would be useful too.
How do you script a dropMouseItem() function?
I need one for a keyring I'm working on.
I would think the way to go about it is t define the key ring as a sack (complete with empty ring and 1,2,3, and 'several' key models and icons); change them out the same way the sack code changes the appearance of the sack.

If you need to force it to be dropped (via script), spawn a surface at the party's feet (ground level), with a connector from it to a function that counts the contents of the surface, and destroys it when the last item is removed from it.

Then loop through the party's inventory until you find the key ring, and add it to the ground surface, and remove it from the party. This should leave it sitting [seemingly] on the ground, and removes the temporary surface whenever the item is picked up.
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: [SOLVED] multiple clickable component

Post by Zo Kath Ra »

Isaac wrote:If you need to force it to be dropped (via script), spawn a surface at the party's feet (ground level), with a connector from it to a function that counts the contents of the surface, and destroys it when the last item is removed from it.

Then loop through the party's inventory until you find the key ring, and add it to the ground surface, and remove it from the party. This should leave it sitting [seemingly] on the ground, and removes the temporary surface whenever the item is picked up.
Thank you, that works :)

But why doesn't this work?

Code: Select all

function dropMouseItem()
	local mouse_item = getMouseItem()
	
	if (mouse_item ~= nil) then
		local altar = spawn("altar", party.level, party.x, party.y, party.facing, party.elevation)
		altar.surface:addItem(mouse_item)
		setMouseItem(nil)
		
		mouse_item.go:setPosition(party.x, party.y, party.facing, party.elevation, party.level)
		
		altar:destroy()
	end
end
When I pick up the dropped mouse item, LoG2 crashes with this error:

Code: Select all

[string "Party.lua"]:0: attempt to perform arithmetic on field 'x' (a nil value)
stack traceback:
	[string "Party.lua"]: in function 'canReach2'
	[string "Item.lua"]: in function 'onClickComponent'
	[string "GameMode.lua"]: in function 'mousePressed'
	[string "GameMode.lua"]: in function 'update'
	[string "Grimrock.lua"]: in function 'display'
	[string "Grimrock.lua"]: in main chunk
Post Reply