Weird glitch between hooks and script_entity objects

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: Weird glitch between hooks and script_entity objects

Post by nichg »

I think I have a sane way to pass certain things to script_entities from hooks. I've had decent luck using '.' instead of ':'. For instance, the stuff I was talking about earlier in this thread works consistently for me if I do:

script_library

Code: Select all

function checkChampionEquip(champ_id, itemname)
   champ = party:getChampion(champ_id)
   for i=1,10 do
      if champ:getItem(i):name == itemname then
         return true
      end
   end
end
OnDamage hook

Code: Select all

onDamage = function(champ, dmg, dmgtype)
   if script_library.checkChampionEquip(champ:getOrdinal(), "senvelor_shield") then
      -- do stuff!
   end
end
Whereas it crashes and gives me weird references if I did script_library:checkChampionEquip(...). I'm not sure why, but you might find this fixes your bug.
User avatar
zalewapl
Posts: 45
Joined: Sun Apr 22, 2012 12:39 am

Re: Weird glitch between hooks and script_entity objects

Post by zalewapl »

Oh silly me, I've figured out why the game was crashing. I completely forgot I had an onDie hook that looked like this:

Code: Select all

	onDie = function(champion)
		local CHAMPION_DEATH_PRICE = 1000
		scoreLua.score = scoreLua.score - CHAMPION_DEATH_PRICE
		print ("Score " .. scoreLua.score)
	end,
Still, that's not a real reason for a nasty CTD so I still believe that there is a bug somewhere. The game shouldn't crash here. Instead it should point out what I did wrong.
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: Weird glitch between hooks and script_entity objects

Post by nichg »

Try doing something like this instead:

scoreLua

Code: Select all

function decrementScore(ammt)
   score = score - ammt
end

function getScore()
   return score
end
onDie

Code: Select all

onDie = function(champion)
   -- ...
   scoreLua.decrementScore(ammt)
end
Use scoreLua.getScore() when you want to access it. I've found I had to do that with a timer on a featherfall potion I have that has to tie into onMove to correctly count down for puzzles/etc.
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Weird glitch between hooks and script_entity objects

Post by Xanathar »

  • Whereas it crashes and gives me weird references if I did script_library:checkChampionEquip(...).
You have to call it with a "." not a ":".

If you call a method with a ":" it receives what's before the ":" as the first argument and thus you'll end up having all the function arguments shifted by one (thus the error).
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: Weird glitch between hooks and script_entity objects

Post by nichg »

Aha, good to know why it happens. I guess then it could also affect other bits of code where one script calls another directly. And all of Grimrock's functions for objects always expect a self to be passed to them. Okay, that makes sense.
User avatar
zalewapl
Posts: 45
Joined: Sun Apr 22, 2012 12:39 am

Re: Weird glitch between hooks and script_entity objects

Post by zalewapl »

Yeah, that explains a lot. I feel really ashamed now for making such basic mistakes.
Post Reply

Return to “Modding”