How can I make an Object Un-Detectable through LUA

Typically: "How do I... ", "How can I... " questions
Post Reply
ItzShiiFt
Posts: 2
Joined: 02 May 2024, 19:35

How can I make an Object Un-Detectable through LUA

Post by ItzShiiFt »

Hi, I'm new to Lua and CoppeliaSim.

I am attempting to change an Objects 'Detectable' Special Property to false (unchecked) in Lua for a specific event. Having the Objects Detectable property change to true from false works with this line:
'sim.setObjectSpecialProperty(objectHandle, sim.objectspecialproperty_detectable)'

However, I can't seem to find a way to do it so it changes it from true to false. Does anybody know how to do this, only through Lua code not through the Interface. I know its a weird request.

Thanks.

fferri
Posts: 1242
Joined: 09 Sep 2013, 19:28

Re: How can I make an Object Un-Detectable through LUA

Post by fferri »

Object special property value is a bit mask.

To set the detectable flag:

Code: Select all

local oldVal = sim.getObjectSpecialProperty(objectHandle)
sim.setObjectSpecialProperty(objectHandle, oldVal | sim.objectspecialproperty_detectable)
To clear the detectable flag:

Code: Select all

local oldVal = sim.getObjectSpecialProperty(objectHandle)
sim.setObjectSpecialProperty(objectHandle, oldVal & ~sim.objectspecialproperty_detectable)
Note:

& is bit-wise AND
| is bit-wise OR
~ is unary bit-wise NOT

See also: https://www.lua.org/manual/5.3/manual.html#3.4.2


Btw, you can use a value of 0 to indicate none of the bits set:

Code: Select all

sim.setObjectSpecialProperty(objectHandle, 0) -- remove all bits

ItzShiiFt
Posts: 2
Joined: 02 May 2024, 19:35

Re: How can I make an Object Un-Detectable through LUA

Post by ItzShiiFt »

That worked, Thank you.

Post Reply