Problem with random obstacles in a scene

Typically: "How do I... ", "How can I... " questions
Post Reply
skruzic
Posts: 3
Joined: 16 Oct 2018, 10:12
Location: Split, Croatia

Problem with random obstacles in a scene

Post by skruzic »

Hello,

I'm trying to create a scene with randomly scattered simple obstacles (for now, only static cuboids of fixed size). I achieve this by attaching a non-threaded child script to the cuboid object and write it's init function as follows (object is called Cuboid01):

Code: Select all

function sysCall_init()
    cuboidHandle = sim.getObjectHandle('Cuboid01')
    gndHandle = sim.getObjectHandle('ResizableFloor_5_25')
    position = {math.random()*20-10,math.random()*20-10,0.5}
    orientation = {0,0,math.random()*math.pi/2}
    sim.setObjectPosition(cuboidHandle,gndHandle,position)
    sim.setObjectOrientation(cuboidHandle,gndHandle,orientation)
end
This works well when it is the only object in the scene. However, when I copy-paste it, of course it gets suffix #0, #1, etc., but when simulation is run I get the error:

Code: Select all

Lua runtime error: [string "CHILD SCRIPT Cuboid01#0"]:29: Object does not exist. (sim.getObjectHandle)
stack traceback:
	[C]: in function 'getObjectHandle'
	[string "CHILD SCRIPT Cuboid01#0"]:29: in function <[string "CHILD SCRIPT Cuboid01#0"]:1>
This is not in line with http://www.coppeliarobotics.com/helpFil ... bjects.htm, which claims that (adapted to suit object names from my scene)
When you duplicate Cuboid01, the copy will be named Cuboid01#0. In that case the duplicated script remains identical to the original script, however the duplicated script will know that is must access Cuboid01#0 and not Cuboid01.
Any help with this will be appreciated. Thanks!

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

Re: Problem with random obstacles in a scene

Post by fferri »

The error happens when getting the handle of "ResizableFloor_5_25".
You need to use

Code: Select all

sim.getObjectHandle('ResizableFloor_5_25#')
(note the trailing # character) to avoid automatic name adjustment.

Post Reply