duplicated object script cannot find other objects by sim.getObjectHandle()

Report crashes, strange behaviour, or apparent bugs
Post Reply
pwyq
Posts: 18
Joined: 28 May 2021, 19:30

duplicated object script cannot find other objects by sim.getObjectHandle()

Post by pwyq »

Hi, in CoppeliaSim 4.2.0 (I haven't tested this with 4.3.0), I found that when I duplicate a robot, the new one is appended a string '#0' (as expected). The child script can get the handle of the robot itself (such as sim.getObjectHandle('robot#0')), but it fails to find any other objects other than the components of the duplicated robot. After I rename the duplicated robot from "robot#0" to "robot_2", the problem disappears. I doubt that the hashtag "#" is messing up with the sim.getObjectHandle.

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: duplicated object script cannot find other objects by sim.getObjectHandle()

Post by coppelia »

Hello,

in CoppeliaSim versions prior to V4.3, you would use a unique object name to identify an object. Additionally, in order to enable scripts to automatically operate even after duplication, there was an automatic name adjustment mechanism, e.g.:

From script "robot#42" if you called:
  • handle=sim.getObjectHandle("sensor"), you would get the handle of object "sensor#42" (i.e. "#42" automatically appended)
  • handle=sim.getObjectHandle("sensor#36"), you would get the handle of object "sensor#36"
In the first above example, the sensor would be different for each copy of the robot model, since the robot model's name suffix would automatically change (e.g. "robot#43" --> "sensor#43", "robot#44 --> "sensor#44", etc.). In the second example, the sensor would be hard-wired, i.e. always the same, even in a robot model copy (e.g. "robot#43" --> "sensor#36", "robot#44 --> "sensor#36", etc.)

In CoppeliaSim V4.3 and later, objects have non-unique aliases, and you can easily access any object via an absolute or relative path to the object. See here about details on how to access objects programmatically.

Cheers

Post Reply