You need to log in to create posts and topics.

getLinkedValue() in script ?

Hello !

In the "Linked component" page, it says that scripted components can be linked. But, how can we retrieve the linked value? There is no getLinkedValue() function?

But, how can we retrieve the linked value? There is no getLinkedValue() function?

No, there is no getLinkedValue() function.
A component can send data to others, not retrieve.
What each component can do is listed in the page you merntioned: https://simulide.com/p/linking-components/

I am simulating a heating resistor / NTC thermistor pair.

Both components are scripted components.
The heating resistor calculates the temperature based on its dissipated power.
The thermistor must retrieve this temperature. But how?

Desired scenario: the resistor links the thermistor (resistor = linker, thermistor = linked). The resistor does setLinkedValue(). But how from the thermistor script to retrieve the value?

Finally, I found a workaround ...
The thermistor links the resistor (thermistor = linker, resistor = linked). The resistor has a "secret" property called "Temperature" that is updated by the resistor script. The thermistor uses getPropStr(0, "Temperature) to retrieve this property, then parseFloat() it to retrieve the temperature.

Uploaded files:

You can do much simpler and efficient than using Property + parseFloat().

Following what happens in the circuit:
The resistor emits heat, so just link resistor to thermistor and resistor sends data to thermistor.

How to do:
Resistor links to thermistor, it has index 0 (there is no other component linked).
in resistor script, when voltage changes call:

component.setLinkedValue( 0, heatData, 0 ); // This will call thermistor script

 

 

Then in thermistor script you implement the function that will be called:

void setLinkedValue( double heatData, int i )
{
    double current = heatData*k; // Do whatever you want with heatData
    // You can also use parameter int i for whatever you want
}

 

 

Ah OK ! Thanks.

This is what I was looking for. 

It's more a kind of callback function than if the linked component has to retrieve the value. Understood.

arcachofo has reacted to this post.
arcachofo