I'm sorry if this seems like a simple question but I've been unable to find the answer so far.
How do I add a hook?
For example, what's the syntax to add an onAttack hook to the party?
Something like:
party.part:onAttack = function( <parameters>...)
doMySpecialThing...
end
Thanks for any help
How to add a hook
- cromcrom
- Posts: 549
- Joined: Tue Sep 11, 2012 7:16 am
- Location: Chateauroux in a socialist s#!$*&% formerly known as "France"
Re: How to add a hook
Instead of feeding you a fish, I will teach you how to fish, and make you a free man, instead of being a slave to others: type onAttack, or onMove, or onDie, in the search box of the forum, and look for examples, there are tens of them here and there.
A trip of a thousand leagues starts with a step.
Re: How to add a hook
OK, I tried to search for the term before I posted here.
I can't find an example of how to hook up the function that works in grimrock 2.
I've seen examples of something like this:
added to objects.lua but when I try that I get the following error on dungeon load:
mod_assets/scripts/objects.lua:5: attempt to call global 'cloneObject' (a nil value).
Most of the examples I've seen are from before G2 was released so I assume they are for G1 and the scripting syntax has changed in G2.
I can't find an example of how to hook up the function that works in grimrock 2.
I've seen examples of something like this:
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(self, champion, action, slot)
hudPrint("Attacking")
end,
}
mod_assets/scripts/objects.lua:5: attempt to call global 'cloneObject' (a nil value).
Most of the examples I've seen are from before G2 was released so I assume they are for G1 and the scripting syntax has changed in G2.
Re: How to add a hook
Links to my YouTube playlist of "tutorials" and to my forum thread.
Re: How to add a hook
That's exactly what I needed.
Thanks!
Thanks!
Re: How to add a hook
That's working well but now I have another question.
In Jgwman's scripts, he defines the onAttack hook as follows:
but the scripting reference shows that onAttack has the following signature:
I modified the code to use the latter signature and it is called with no errors. However, I'm not sure what is in the 'action' parameter.
type(action) returns 'table' but the following code prints nothing:
Anyone know which is the correct signature or, if both are fine, what's supposed to be in the action parameter?
Thanks
In Jgwman's scripts, he defines the onAttack hook as follows:
Code: Select all
onAttack = function(party, champion, weapon)
...
end
Code: Select all
onAttack(self, champion, action, slot)
type(action) returns 'table' but the following code prints nothing:
Code: Select all
for key,value in pairs(action) do
hudPrint(key, value)
end
Thanks