debugDraw

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!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

debugDraw

Post by RayB »

I have used debugDraw and it really helps but I can only get the debug box to show if used in the dungeon.
If I try to use it in an outside area the box does not show. Is there any way to get the debug box to show when used on a level that is outside ie. a forest level containing a forest_sky and heightmap?
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: debugDraw

Post by 7Soul »

It doesn't work if the map has water in it
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

I find the discord server much too difficult to use. Tried it. Tried to post a question but I don't think it worked. Gave up!
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

Thank you for the info.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

I have set up a receptor which accepts any entity and a script which checks for various poison bolts.
If it was a poison bolt that hit the receptor a spear door will open.

Everything worked fine until I placed a skeleton archer in the room. If I am standing by the receptor and
dodge one of his arrows and the arrow hits the receptor, an error saying 'bad object' is generated.

I thought that maybe the arrow was getting destroyed before the function was called but that doesn't
see tot be the case...
The function arguments are '( _, type )' and when I print(type) from within the function the print shows
that type' is a table yet if I print( type.name ) I get the bad object error.

Any other object I throw at the receptor works. I even shot an arrow at it printed that it was an arrow that
hit it. Only the arrow that the archer shoots gives the crash and 'bad object' error.

Any solution to this or should I simply not use a skeleton archer in this room.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: debugDraw

Post by minmay »

If you get an error saying "bad object", that means the object has already been destroyed, yes, and skeleton archer arrows (and medusa arrows, and trickster rocks) are indeed destroyed before a WallTriggerComponent's onActivate connector triggers. References to destroyed objects can still exist, but any attempt to index them other than indexing their class's methods, pass them to functions that expect an object, or assign keys to them will result in that error.

(In this context, "object" can mean a GameObject, like in this case, or a Component or other class like Champion or Map; they all have this in common).

There are a few workarounds you could use to ensure that the object hasn't been destroyed before sending it to your script. I think the easiest one would be to use this onActivate hook in the definitions of all your WallTriggerComponents:

Code: Select all

onActivate = function(self, entity)
	-- Ensure the triggering entity is on the map, preventing already-destroyed objects (fragile ItemComponents, mainly) from triggering connectors.
	for e in self.go.map:allEntities() do
		if e == entity then
			return true
		end
	end
	return false -- Do not trigger connectors
end
(If you know your wall trigger can only be hit by projectiles in a few specific squares - most wall triggers can only be hit by projectiles in their own square unless you are using extreme projectile speeds, extreme time multipliers, or huge projectile colliders - then you can use one or a few entitiesAt() calls instead of allEntities() here, of course, which is faster in some circumstances, but as most dungeons will never have multiple wall triggers being triggered on the same frame, such an optimization is unlikely to be useful.)
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.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

Once again. Thank you for the good advice.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

I am trying to remove an item from my trickster monster. In the inspector window I gave him an iron key and set its id to 'trap_door_key'. If you kill him before he opens the door, he drops the key so the player can use it to open the door. but If he gets to the door and opens it himself I would like to remove the key from his inventory so he won't drop it when you kill him.

I tried - 'tomeRoomTrickster.monster:removeItem("iron_key")' and also 'tomeRoomTrickster.monster:removeItem("trap_door_key")' but both give an error saying item component expected got ???. I have tried indexing both of these with a '.item' added on but nothing works.

Could I please get the correct code for this.

Also, I have tried to print 'tomeRoomTrickster.monster:getLootDrop()' before killing him and after he is dead and drops the loot but it always prints nil.

Also, findEntity("trap_door_key") returns nil if the key is in the monsters inventory.

How can I access a monsters loot?
User avatar
Isaac
Posts: 3167
Joined: Fri Mar 02, 2012 10:02 pm

Re: debugDraw

Post by Isaac »

If you use the openLockWith() brain method, and include the key name, it will auto-destroy the key item after opening the lock.

Code: Select all

trickster_1.brain:openLockWith("lock_gold_1", "trickster_gold_key") 

Code: Select all

--Placed inside script entity

	trickster_1.monster:addItem(spawn("gold_key",nil,nil,nil,nil,nil,"trickster_gold_key").item)
	trickster_1.brain:addConnector("onThink", self.go.id, "unlock")
	
	function unlock()
		if trickster_1.brain:here("lock_gold_1") and trickster_1.brain:carrying("trickster_gold_key") then 
			trickster_1.brain:openLockWith("lock_gold_1", "trickster_gold_key") 
		end
	end
Last edited by Isaac on Fri Jan 19, 2024 6:03 am, edited 1 time in total.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: debugDraw

Post by RayB »

Thank you!
Post Reply