Ask a simple question, get a simple answer
Re: Ask a simple question, get a simple answer
Yes.
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
I haven't seen a crash with this ...yetminmay wrote:Actually it will either return the GameObject or it will crash, since if the object doesn't exist, you will get an error when you try to index caller (since it doesn't exist).Isaac wrote:findEntity(caller.go.id) returns either the caller object or nil; but the caller object is already available in the function.
Code: Select all
function destroyCaller(caller)
if caller and caller.go and caller.go.timer then
caller.go:destroyDelayed()
end
print(caller, 'destroyed')
end
When I call script_entity_4.script:destroyCaller() I get 'table: <whatever the name> destroyed' as the expected output.
Re: Ask a simple question, get a simple answer
Yes, that won't crash, because you check for the existence of caller before you try to index it.
Actually I guess findEntity(caller.go.id) could return nil in the very specific cases that:
1. caller is a component that exists, but its parent GameObject is not on a map (perhaps it's an item inside an inventory)
or 2. caller is not a component, but is a table with a "go" field that is a table with an "id" field that contains a string that is not the id of any GameObject that exists on a map
But if caller or caller.go don't exist (or they aren't tables), or caller.go.id is not a string, then you're just going to get an error when you try to index them/pass a non-string.
Actually I guess findEntity(caller.go.id) could return nil in the very specific cases that:
1. caller is a component that exists, but its parent GameObject is not on a map (perhaps it's an item inside an inventory)
or 2. caller is not a component, but is a table with a "go" field that is a table with an "id" field that contains a string that is not the id of any GameObject that exists on a map
But if caller or caller.go don't exist (or they aren't tables), or caller.go.id is not a string, then you're just going to get an error when you try to index them/pass a non-string.
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
But of course, that's the reason for it.minmay wrote:Yes, that won't crash, because you check for the existence of caller before you try to index it.
Aha. This I can certainly see, but it seems probably impossible to happen without the modder knowing about it in advance; an issue only for second party modders that are using large scripts from someone else, and/ or they don't know how they work. How does anyone get an object like that in their mod... one that would have that structure... if they didn't add it themselves. One would have to create the thing and setup the call to the destroy function to get the error.But if caller or caller.go don't exist (or they aren't tables), or caller.go.id is not a string, then you're just going to get an error when you try to index them/pass a non-string.
Re: Ask a simple question, get a simple answer
Of course.
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
Which is exactly what was happening from the very beginning of this particular discussionminmay wrote:Yes, that won't crash, because you check for the existence of caller before you try to index it.
Re: Ask a simple question, get a simple answer
no it wasn't...
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
It most certainly was, crom's original code to make the call is,"bandagetimer.timer:addConnector("onActivate", "destroy_timer", "destroyCaller","bandage_applied" )
Which means that the Timer Component is ALWAYS passed as the caller. There is no need to say, "if caller" in this scenario. If the Timer Component didn't exist, then the onActivate method for that very timer would never trigger.
*EDIT*
Case in Point:
In the Nexus Campain, the official script on the Barren Dessert to handle a Golemn's Death is:
And this is attached to the Golem with a simple connecter. As you can see, there is no need to say "if sender" before Almost Human typed "sender.go"
Which means that the Timer Component is ALWAYS passed as the caller. There is no need to say, "if caller" in this scenario. If the Timer Component didn't exist, then the onActivate method for that very timer would never trigger.
*EDIT*
Case in Point:
In the Nexus Campain, the official script on the Barren Dessert to handle a Golemn's Death is:
Code: Select all
function golemDie(sender)
sender.go:spawn("power_gem")
end
Re: Ask a simple question, get a simple answer
I was specifically commenting on Isaac's statement here, which is why I quoted it:
Of course you do not need to check for the parameter's existence if you are always passing it in the first place. Like, duh. Sorry for any confusion.Isaac wrote:findEntity(caller.go.id) returns either the caller object or nil; but the caller object is already available in the 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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
- AndakRainor
- Posts: 674
- Joined: Thu Nov 20, 2014 5:18 pm
Re: Ask a simple question, get a simple answer
Is there any way to deactivate the throwing of mouse item ? I made a small window where I would like to drag and drop items, but when I click on it the mouse item is thrown.