How to define global variable? (Kilobot robot)

Typically: "How do I... ", "How can I... " questions
Post Reply
Yehia Soliman
Posts: 12
Joined: 21 Jul 2019, 12:33

How to define global variable? (Kilobot robot)

Post by Yehia Soliman »

Hi

how to define global variable where all kilobots robots scripts can see this variable in V-REP?

thanks in advance.

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

Re: How to define global variable? (Kilobot robot)

Post by coppelia »

Hello,

you have several possibilities. Simplest is to define an integer, float or string signal:
Using a string signal you can basically convey or share any type of data, for instance:

Code: Select all

local myDataStructure={}
myDataStructure.id=42
myDataStructure.data={1,2,"Hello"}
sim.setStringSignal("myStringSignal",sim.packTable(myDataStructure))
Cheers

Yehia Soliman
Posts: 12
Joined: 21 Jul 2019, 12:33

Re: How to define global variable? (Kilobot robot)

Post by Yehia Soliman »

Excuse me, can you give me an example, please? or where can I write the global variable that allow all kilobots child scripts see it?

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

Re: How to define global variable? (Kilobot robot)

Post by coppelia »

e.g. if you want to share a floating value, you would write and read that variable with:

Code: Select all

-- write:
sim.setFloatSignal("myFloatSignal",value)

-- read:
local value=sim.getFloatSignal("myFloatSignal")
Cheers

Post Reply