I made a small script into a empty scene to test understand how to use tables to store data I'll use later in my research to pick and place random objects created on-the-fly. The code follows:
Code: Select all
function sysCall_init()
sim = require('sim')
-- Put some initialization code here
-- sim.setStepping(true) -- enabling stepping mode
end
function sysCall_thread()
-- Put your main code here, e.g.:
--
while not sim.getSimulationStopping() do
if sim.getBufferSignal("mp") then
mp=sim.getBufferSignal("mp")
mp=sim.unpackTable(mp)
if mp[table.getn(mp)]==nil then
table.insert(mp,1)
else
table.insert(mp,mp[table.getn(mp)]+1)
end
print(mp[table.getn(mp)])
print("n="..table.getn(mp))
sim.setBufferSignal("mp",sim.packTable(mp))
else
mp={}
sim.setBufferSignal("mp",sim.packTable(mp))
end
end
end
-- See the user manual or the available code snippets for additional callback functions and details
sometimes I get it until the 5th row, sometimes 4th, sometimes I get 15 rows and sometimes 16...[/script:error] ...rogram Files/CoppeliaRobotics/CoppeliaSimEdu/lua/sim.lua:1850: invalid input data.
stack traceback:
[C]: in function 'error'
...rogram Files/CoppeliaRobotics/CoppeliaSimEdu/lua/sim.lua:1850: in function 'sim.unpackTable'
[string "/script"]:16: in function 'sysCall_thread'
stack traceback:
[C]: in function 'error'
...ogram Files/CoppeliaRobotics/CoppeliaSimEdu/lua/base.lua:464: in function <...ogram Files/CoppeliaRobotics/CoppeliaSimEdu/lua/base.lua:453>
Any ideas on what the problem is?