## difficulties with simSetGraphUserData

Typically: "How do I... ", "How can I... " questions
richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

### difficulties with simSetGraphUserData

(Running Ubuntu)
I do not understand the Invalid data stream error. I seem to be generating correct data.

In a child script, in the initialisation section, I have
gHandle=simGetObjectHandle("Graph") -- refers to a graph object that is a child to the object associated with the script

In the actuation section, I have at line 56-57
simAddStatusbarMessage(string.format("F Left: %f, Right: %f\n",leftV, rightV))
simSetGraphUserData(gHandle, "LeftAV", leftV)

This appears to be compliant with the function spec:
Lua synopsis number result=simSetGraphUserData(number graphHandle,string dataStreamName,number data)

During an animation, the following is produced in the status bar (on each iteration, it seems).

F Left: -0.820305, Right: -0.731991
Lua runtime error: [string "SCRIPT Mob_Base"]:57: Invalid data stream. (simSetGraphUserData)
stack traceback:
[C]: in function 'simSetGraphUserData'
[string "SCRIPT Mob_Base"]:57: in main chunk

Since leftV has a valid number, which is printed into the Status Bar, why is it invalid as part of a data stream?

coppelia
Posts: 7605
Joined: 14 Dec 2012, 00:25

### Re: difficulties with simSetGraphUserData

Hello,

Are you sure your data stream type is "Various: user-defined"?
If yes, then please post your scene, it will be easier to track the problem.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

### Re: difficulties with simSetGraphUserData

a) What is the best way to 'post a scene'? Do you prefer pastebin, or attach a .ttt file?
Here is pastebin url http://pastebin.com/Dkn1M1gT

b) When you say <Are you sure your data stream type is "Various: user-defined"?>, which context do you mean?
In the Graph Object, I have set the datastream resource to "Various: user-defined", but the problem seems to be associated with my child script. It is complaining about the number I am giving it as an invalid data stream.

Is there some way that I have to create a data stream inside the child script?

coppelia
Posts: 7605
Joined: 14 Dec 2012, 00:25

### Re: difficulties with simSetGraphUserData

You cannot create new data streams via API calls.

Have a look at this scene, that uses user-defined data streams.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

### Re: difficulties with simSetGraphUserData

I sent you a pastebin link. This is the same. No?

coppelia
Posts: 7605
Joined: 14 Dec 2012, 00:25

### Re: difficulties with simSetGraphUserData

I can't seem to be able to download the file in a simple manner via pastebin.
Did you have a look at the link I provided?

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

### Re: difficulties with simSetGraphUserData

Understand about pastebin not working for you.
Here is the scene in DropBox https://www.dropbox.com/s/0ole5spt9u2ln ... e.ttt?dl=0

I looked at the scene you sent, but it seems to use a different technique for graphing, not simAddGraphUserData. Very interesting.

coppelia
Posts: 7605
Joined: 14 Dec 2012, 00:25

### Re: difficulties with simSetGraphUserData

The scene I posted used simSetGraphUserData. The same API command as you do. simAddGraphUserData is not a valid API command.

Also, in your scene you have:

Code: Select all

simSetGraphUserData( gHandle, "LeftV", moveL)

But you don't have a single data stream named LeftV. Either replace it with Data, or rename the data stream to LeftV.

Cheers

richardh
Posts: 28
Joined: 16 Jan 2017, 12:39

### [Solved] Re: difficulties with simSetGraphUserData

I finally figured this one out. Thank you for you help.
a) The scene you posted gave me the clues. (sorry for typo about the function in one of my posts). There are three child scripts in it, and I only looked at two, which is why I said I couldn't find the function. For some reason, I didn't look at the one associated with the graph object. :(
b) The documentation, and your explanation above, is confusing. I finally realised that a "data stream name" is the name set inside the graph object when editing the scene. The default is "Data". So to change the default, I needed to double click on "Data" and change it to the name I wanted. The reason this is a bit confusing is that in all other situations where a script is linked to an object in the scene, it is necessary to explicitly get a handle to an object in the scene before being able to use the object in a script. So the name of the object is mentioned in the script only in the initiation phase and not (typically) in the actuation stage.
Perhaps in the documentation of the function simSetGraphUserData, you could add some words to the description, eg: The name of a data stream is specified in the graph object in the scene (default is 'Data').
c) It is also very unclear that as soon as simSetGraphUserData is used, it is also necessary to use simHandleGraph() with an explicit time at which the datum is to be associated. Perhaps in the description of simSetGraphUserData you could add some words like: Be sure to call simHandleGraph() to record the data and set the graph object to 'explicit handling'.

Regards,
Richard

coppelia