Is it true that triggers/buttons no longer give a "self" ref

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
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Is it true that triggers/buttons no longer give a "self" ref

Post by Isaac »

It used to be that a plate or button could be identified in the function it called; is this no longer the case? ~Or did just the method for this change?

For example:

Image

Code: Select all

function aboutFace(caller)
print(caller.name, caller.id, caller.x, caller.y)
end
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Is it true that triggers/buttons no longer give a "self"

Post by NutJob »

caller.go.id, caller.go.name, etc
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it true that triggers/buttons no longer give a "self"

Post by Isaac »

NutJob wrote:caller.go.id, caller.go.name, etc
Yep; it would be so simple ~after I asked. :mrgreen:
Thanks.

* .go is still so unfamiliar... too often forgotten about.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Is it true that triggers/buttons no longer give a "self"

Post by NutJob »

Not a problem, it got me too a few weeks ago. Don't really understand the reason why it's required but it becomes easy to remember once ya recognize when it's needed, or not needed.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Is it true that triggers/buttons no longer give a "self"

Post by minmay »

It's required because buttons are entities in Grimrock 1, but components in Grimrock 2. So when a button is passed to a script in Grimrock 1, it's an entity with an id, position, etc. When a button is passed to a script in Grimrock 2, it's a component belonging to a game object, so it doesn't have a position or the like; you need to get that from the parent game object with .go.
Passing the component is much better than passing the game object for several reasons (example: consider having a game object with multiple components that connect to the same function).
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.
Post Reply