Page 95 of 396
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 4:12 pm
by Azel
Your bandagetimer addConnector call has 4 parameters, but I thought it only uses 3?
Component:addConnector(event, target, action)
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 4:21 pm
by Azel
cromcrom wrote:
then, when it activates, it calls this function:
Code: Select all
function destroyCaller(caller)
if findEntity(caller) then
findEntity(caller):destroyDelayed()
end
print(findEntity(caller), 'destroyed')
end
However, I have a "could not look up class name " error. Any help, please? I know I could go the rough way, it does work, but I would like to have a broader destroying function, where I can pass the id as an argument.
I was able to get it to work by updating the destroyCaller function as follows:
Code: Select all
function destroyCaller(caller)
local thisCaller = findEntity(caller.go.id);
if thisCaller then
thisCaller:destroyDelayed();
end
print(thisCaller.id, 'destroyed')
end
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 4:27 pm
by cromcrom
It works really great, thanks a lot for taking the time to look into this.
cheers.
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 7:56 pm
by Isaac
cromcrom wrote:Code: Select all
function destroyCaller(caller)
if findEntity(caller) then
findEntity(caller):destroyDelayed()
end
print(findEntity(caller), 'destroyed')
end
However, I have a "could not look up class name " error. Any help, please? I know I could go the rough way, it does work, but I would like to have a broader destroying function, where I can pass the id as an argument.
FindEntity expects a string as input.
Code: Select all
function destroyCaller(caller)
if findEntity(caller.go.id) then
findEntity(caller.go.id):destroyDelayed()
end
print(findEntity(caller.go.id), 'destroyed')
end
Azel wrote:I was able to get it to work by updating the destroyCaller function as follows:
local thisCaller = findEntity(caller.go.id);
Indeed; and it is because with the string id, findEntity ~finds the entity.
________________________
*I would recommend keeping the timer checks from the first example. It means that only timers get destroyed. If you accidentally connect a floor_trigger or another script to this function ~~it gets destroyed... with no errors to trace; once you comment out the print() statement.
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 8:45 pm
by Azel
True, Isaac. I would go one step further to clarify (for other fellow Mod newbies reading this) that the findEntity() method is expecting the Unique ID given to an in-game object. Which is either the name the Modder uniquely assigned the object when placing it in the Mod, or the name the Editor tool auto-assigned (which is typically just the general name with an auto-increment number at the end).
In this case, crom was passing the entire component/object in to the findEntity() method; so all I did was add the syntax to pass that objects Unique ID instead. Fin.
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 9:02 pm
by Isaac
In this particular case... ~caller is [usually] passed to the function; so it [usually] exists. There is not really a need to use findEntity() in this case, as one [usually] already has this entity.
findEntity(caller.go.id) returns either the caller object or nil; but the caller object is already available in the function.
if findEntity(caller.go.id) then is equivalent to
if caller then in the sense that if the object does not exist, we get nil, but if it does exists ~we do not get nil. So this can work with an IF block without calling findEntity at all.
Code: Select all
if caller and caller.go and caller.go.timer then
--do something
end
This checks first for a non-nil caller, then for the .go field, then for the .go.timer fields, and finding them all, considers the object a timer.
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 10:35 pm
by cromcrom
Actually, in the first connector call, I thought the 4th argument ("bandage_applied"), as a the id I created this timer with, would be considered as an id. But I was wrong, and, like you did, azel, had to identify it as an id again. I tryed many things combinations, actually. Iterative intuitive coding at its worst
.
But it works great now. I might change some other parts of my systems, because this seems more robust. Sigh. Thanks again anyways.
Re: Ask a simple question, get a simple answer
Posted: Wed Oct 07, 2015 11:22 pm
by Azel
It's all good crom. Fumbling through the process and making repeated mistakes is the best way to become an expert at something
Re: Ask a simple question, get a simple answer
Posted: Thu Oct 08, 2015 12:22 am
by minmay
Isaac wrote:findEntity(caller.go.id) returns either the caller object or nil; but the caller object is already available in the function.
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).
Also you guys need to be careful about conflating the GameObject and its components. Component.go will always give you the parent GameObject, but GameObject.go will give you nil (unless it has a component named "go", in which case it would obviously give you that, but that probably isn't what you want either).
Re: Ask a simple question, get a simple answer
Posted: Thu Oct 08, 2015 12:42 am
by Azel
Right so that should mean...
When a trigger has a connector to a Script Function, and that function is accepting (as a Parameter) the calling Component (trigger component); then the following will work: caller.go
However, this will not work (it will return NIL) :
local trigger = findEntity("floor_trigger_1");
trigger.go
I think