Part producer creates many parts when I hit the stop button

Report crashes, strange behaviour, or apparent bugs
Post Reply
glebysg
Posts: 5
Joined: 20 Jan 2016, 00:47

Part producer creates many parts when I hit the stop button

Post by glebysg »

I'm working with a part producer that a cube (primitive shape) every 15 seconds
Here is the code

Code: Select all

simSetThreadSwitchTiming(2) -- Default timing for automatic thread switching
simDelegateChildScriptExecution()

h=simGetObjectHandle('Cuboid_model')
wasPreviouslyReadyForPicking=true

while true do 
			-- Save current selection state:
			currentSelection=simGetObjectSelection()
			-- Copy an object:
			simRemoveObjectFromSelection(sim_handle_all,-1)
			simAddObjectToSelection(sim_handle_single,h)
			simCopyPasteSelectedObjects()
			copy=simGetObjectSelection()[1] -- this is the copy
			-- Make the copied object dynamic (i.e. non-static):
			simSetObjectIntParameter(copy,3003,0)
			-- Make the copied object respondable:
			simSetObjectIntParameter(copy,3004,1)
			-- Make the copied object visible:
			simSetObjectIntParameter(copy,10,1+256)
			-- Restore the initial selection state:
			simRemoveObjectFromSelection(sim_handle_all,-1)
			simAddObjectToSelection(currentSelection)
			simSwitchThread()
			simWait(15) -- wait a bit before being able to produce again

end
It works fine during simulation, but when I hit stop, it produces a lot of parts suddenly. This is an image
http://postimg.org/image/da60tdx1b/

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

Re: Part producer creates many parts when I hit the stop but

Post by coppelia »

Hello,

Since you are in a threaded child script, you should check if simulation is still running, or if it is about to stop. You can use following code for that:

Code: Select all

while simGetSimulationState()~=sim_simulation_advancing_abouttostop do
    -- do your stuff
end
Cheers

Post Reply