How to call functions in a script

Typically: "How do I... ", "How can I... " questions
Post Reply
anyu
Posts: 5
Joined: 01 May 2025, 08:57

How to call functions in a script

Post by anyu »

Hello, I recently encountered an issue. I added an RG2 gripper to a UR5 robotic arm and created a new Lua script file under this gripper. I tried using the function sim.callScriptFunction('rg2Close@UR5/RG2', sim.sim_scripttype_childscript, {}, {}, {}, '', sim.simx_opmode_blocking) in the console to call a function within this script, but it reported the following error:
​​"in sim.callScriptFunction: one of the function's argument type is not correct."​​

After fixing the error, it then reported:
​​"sim.callScriptFunction: script does not exist."​​

Another question: Could this be due to incorrect input parameters? I thought I might need to pass the script handle into the function. However, when I tried to retrieve the script handle using scriptHandle = sim.getObjectScript(objectHandle) in the console, it gave me the error:
​​[string "local scriptHandle = sim.getObjectScript(obje..."]:1: attempt to call a nil value (field 'getObjectScript')​​

This problem has been bothering me for a while. I would greatly appreciate your help when you have time. Thank you very much!
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: How to call functions in a script

Post by coppelia »

Hello,

what CoppeliaSim version are you running?
As of CoppeliaSim V4.9, best would be to call your script function with:

Code: Select all

local scriptHandle = sim.getObjectHandle('/UR5/RG2')
sim.callScriptFunction('openClose', scriptHandle)
Keep in mind that in the RG2 model, the script is attached to RG2 and should be addressed as '/UR5/RG2/Script', or whatever name that script has (Starting with CoppeliaSim V4.7, script are stand-alone scene objects on their own)

Cheers
Post Reply