Ask a simple question, get a simple answer

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
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is :)

delayedCall(receiver, delay, msg, parameters)

receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID

Example:
viewtopic.php?f=22&t=8182&start=10#p83174
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I think the repeated killing is coming from the fact that a monster isn't dead until the die-particles are gone...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Ask a simple question, get a simple answer

Post by petri »

THOM wrote:I think the repeated killing is coming from the fact that a monster isn't dead until the die-particles are gone...
Yes, the monster's soul lingers for a few seconds in the level before it's cleaned up, so you should always check isAlive() before calling die().
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Zo Kath Ra wrote:
Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is :)

delayedCall(receiver, delay, msg, parameters)

receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID

Example:
viewtopic.php?f=22&t=8182&start=10#p83174
Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
petri wrote:...so you should always check isAlive() before calling die().
This is good to know. In my case, it is alive. It seems that any use of the variable (in this case named 'monster') causes the the [false?] detection for using a non-existant 'go' field. I have an onDie hook that if I checked/used monster.id in, it would halt at the previous damageTile function (that killed the monster), and give the [seemingly erroneous] error.

It's working with the work-around, but I don't know the reason for the error.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac wrote:
Zo Kath Ra wrote:
Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is :)

delayedCall(receiver, delay, msg, parameters)

receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID

Example:
viewtopic.php?f=22&t=8182&start=10#p83174
Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
delayedCall is like a connector, it tries to call the corresponding method on the object's "controller" component. If the object doesn't have a component named "controller" with a "die" method - and it doesn't - then that delayedCall isn't going to help you.
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.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:delayedCall is like a connector, it tries to call the corresponding method on the object's "controller" component. If the object doesn't have a component named "controller" with a "die" method - and it doesn't - then that delayedCall isn't going to help you.
I understand that. I had written a delayedAction() function (a few weeks ago) that simulates delayedCall, but allows for [sub] components to be given. DelayedAction("object.monster", 1, "die") works with it; but when I noticed that delayedCall seemed to [albeit inconsistently] succeed with some components, I began to wonder if I was missing something about how it worked. If delayedCall(worked for it, then I would not have to define/link to delayedAction() in every mod/or script).
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Ask a simple question, get a simple answer

Post by petri »

btw. I'm not sure if this has been mentioned anywhere, but if I remember correctly (it has been a long time since I touched this code!), you should be able to pass extra arguments after the regular args to delayedCall(). Those extra args will be passed to the receiver function. Useful when a function needs to be called with diferent parameters. Just something to keep in mind.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

petri wrote:btw. I'm not sure if this has been mentioned anywhere, but if I remember correctly (it has been a long time since I touched this code!), you should be able to pass extra arguments after the regular args to delayedCall(). Those extra args will be passed to the receiver function. Useful when a function needs to be called with diferent parameters. Just something to keep in mind.
It is the case; since the patch. It's been a boon.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Isaac wrote:Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
What I meant was:
You put a script entity called "script_entity_1" with this function in your mod:

Code: Select all

function killMonster(id)
	local entity = findEntity(id)
	
	if (entity) and (entity.monster) and (entity.monster:isAlive()) then
		entity.monster:die()
	end
end
And call it like this:

Code: Select all

delayedCall("script_entity_1", 0, "killMonster", "forest_ogre_1")
It not exactly what you were asking for, but it's simpler than spawning a new timer.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Ask a simple question, get a simple answer

Post by Drakkan »

I have to say this thread is quite a mess, but it is probably one of the most helpful thread around. RIP NutJob.
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply