Page 1 of 1
help needed: triggering only with specific item in mouse
Posted: Sun Mar 08, 2015 1:35 am
by THOM
Well - again one of my strange posts...
I want a script to be started if geting up a specific object from a floortrigger - only if it's this object.
What I have tried is connecting the trigger "by item only" "on deactivate" with
Code: Select all
function checkOnUp1()
if getMouseItem("torch") then
counter_tree_1.counter:decrement()
end
end
Sadly the script runs even it is any item in the mouse. What to do?
Re: help needed: triggering only with specific item in mouse
Posted: Sun Mar 08, 2015 1:42 am
by minmay
getMouseItem() doesn't take any arguments. It returns the item held. What you wanted is:
Code: Select all
if getMouseItem() and getMouseItem().go.name == "torch" then
Re: help needed: triggering only with specific item in mouse
Posted: Sun Mar 08, 2015 2:22 am
by THOM
ah - thanx.
sigh, scripting is not easy these days...
why do I need
Code: Select all
if getMouseItem() and getMouseItem().go.name == "torch" then
and not
Code: Select all
if getMouseItem().go.name == "torch" then
?
Re: help needed: triggering only with specific item in mouse
Posted: Sun Mar 08, 2015 2:35 am
by minmay
Because if the player is not holding an item in the mouse, getMouseItem() will return nil. You can't index nil. You can only index tables.
Re: help needed: triggering only with specific item in mouse
Posted: Thu Apr 30, 2015 9:57 pm
by Zo Kath Ra
Since we have to use getMouseItem().go.name instead of getMouseItem().name, I guess that means getMouseItem() returns a component. Not an entity like you would expect, and like it did in LoG1:
viewtopic.php?f=14&t=3472&p=35426&hilit ... tem#p35426
Which component does it return, and why doesn't it return the entity?
Re: help needed: triggering only with specific item in mouse
Posted: Thu Apr 30, 2015 10:54 pm
by minmay
It returns the ItemComponent held by the mouse. It does so because it's named "getMouseItem" and you'd expect a function named "get...item" to return an item.
Re: help needed: triggering only with specific item in mouse
Posted: Thu Apr 30, 2015 11:25 pm
by Isaac
THOM wrote:
why do I need
Code: Select all
if getMouseItem() and getMouseItem().go.name == "torch" then
and not
Code: Select all
if getMouseItem().go.name == "torch" then
?
Just to further clarify what it does... getMouseItem() can return nil; if it does, then getMouseItem().go will cause a halt. By first checking for nil, the second check never happens unless getMouseItem() returned other than nil.