Page 3 of 3

Re: [SOLVED] multiple clickable component

Posted: Thu May 28, 2015 7:30 pm
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.

Re: [SOLVED] multiple clickable component

Posted: Thu May 28, 2015 8:37 pm
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.

Re: [SOLVED] multiple clickable component

Posted: Thu May 28, 2015 8:45 pm
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...

Re: [SOLVED] multiple clickable component

Posted: Thu May 28, 2015 10:08 pm
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?

Re: [SOLVED] multiple clickable component

Posted: Sun May 31, 2015 10:58 am
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.

Re: [SOLVED] multiple clickable component

Posted: Sun May 31, 2015 6:11 pm
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.

Re: [SOLVED] multiple clickable component

Posted: Mon Jun 01, 2015 3:05 pm
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