Typically: "How do I... ", "How can I... " questions
Posts: 36
Joined: 24 Dec 2014, 09:25

Hey Every one . I have a function written in a threaded Script i want to use it in such a way that whenever a sensor reads a value then if that value falls in the desired range then that function of the threaded script must be called .How can i do that . Its like a thread in C++ which in continuously keeping track of a particular change.
Any help will be really appriciated.

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

Hi

if the function you want to use is in the same threaded script as the rest of your code (i.e. where you read the sensor)

Code: Select all

function myFunction(param)
--do something
end

while 1 do

--checking if the force sensor val is falling into the range
if forecVector[1]> triggerVal then
myFunction()
end
end
end

-- Put some initialization code here:

-- Here we execute the regular thread code:
if not res then
end

If the code that reads a proximity sensor (and the time it occurred) is in an other (non threaded) script and the threaded script with the function is in a separate script you can use for example signals to communicate within the scripts :

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
h=simGetObjectHandle('Proximity_sensor')
end

if (sim_call_type==sim_childscriptcall_sensing) then
if sensorData==1 then --the sensor read something
--sending the time of the reading through a signal
simSetStringSignal('proxySignal',string.format('%i',simGetSystemTimeInMilliseconds()) )
end
end

The threaded script with the function:

Code: Select all

function myFunction(param)
end
while 1 do
sensorData=simGetStringSignal("proxySignal")
--checking if the force sensor val is falling into the range
if sensorData~=nil then
--we have some sata in the signal so we get it and clean it
simClearStringSignal('proxiSignal')
myFunction(sensorData)
end
end
end
-- Put some initialization code here:

-- Here we execute the regular thread code:
if not res then
end


Cheers

Eric

Posts: 36
Joined: 24 Dec 2014, 09:25