The "Has anyone got this code to work?" thread

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
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: The "Has anyone got this code to work?" thread

Post by JKos » Mon Nov 24, 2014 11:20 pm

Like minmay said, the item is not in a map when it's in a champion slot, and for some reason triggerConnectors tries to access the item's map field which is nil in that case. So this is a bug (or a feature :) ) and should be reported to AH, I'm pretty sure that we can't do anything about this.

edit:
you can test it by placing for example a dagger_1 on your map, then in console call print(dagger_1.map) should print table0x34234243 or something.
the in dagger onEquip-hook try to print map again

Code: Select all

onEquipItem = function(self, champion, slot) 
			print(self.go.map) 
end,
and you will get nil.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: The "Has anyone got this code to work?" thread

Post by NutJob » Mon Nov 24, 2014 11:33 pm

Aye, yes. The first thing I did when I got the map is nil error was this:

Code: Select all

function specialRope(x, y, z, facing)
	local o = spawn("rope", party.level, x, y, facing, z)
	print(o.map)
	o.item:addConnector("onEquipItem", "lib", "aaa")
	o.item:addConnector("onUnequipItem", "lib", "bbb")
	print(o.map)
end
Both give me the same table.

User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: The "Has anyone got this code to work?" thread

Post by Doridion » Tue Nov 25, 2014 10:33 am

I'll place this as a bug in the superthread ;)

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: The "Has anyone got this code to work?" thread

Post by NutJob » Tue Nov 25, 2014 7:39 pm

Thanks Doridion, I can pretty much confirm using addConnector (on the correct field) on an item, only, will produce this error. I just tried added an event to many weapons, armor, and gear, starting with meleeattack on a long sword and I get map is nil.

I use add/removeConnector() (not in the editor but manually in scripts) hundreds of times in my module with everything from the party to push blocks to floor/plate triggers to doors and buttons but it seems items refuse to accept these events. Again, any of these hooks will work fine if they're added using defineObject in the Class block.

FYI to those wondering why I manually script all my event hooks and don't just use the editor: because I use a loader that pulls all my external files into the game, the editor doesn't recognize there's functions inside the file; so the drop down menu never gets populated with all the functions in these external files. Not looking for a fix for this though. I prefer this method and it helps force me to remain organized. ha! ~cheers~

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: The "Has anyone got this code to work?" thread

Post by NutJob » Thu Nov 27, 2014 10:18 pm

Does anyone out there have version .9 or .13?

Post Reply