Torque

Forums

Forums

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » createSensor variable undefined

Pages: [1]
Author Topic: createSensor variable undefined
oliverClimbs
Member
Posts: 10
Post createSensor variable undefined
on: May 13, 2023 (GMT)

When the following code runs during Torque startup, the log displays “variable tripADir is undefined” for the “var dir =” line. When I reload the script, there is no error.

main = function() 
{
  var tripA = Sensor.createSensor("Trip Bank A Distance","Trip A","km");
  var tripATime = Sensor.createSensor("Trip Bank A Time","Trip A Time","s");
  var tripADir = Sensor.createSensor("Trip Bank A Up Down","Trip A + -","");
   
  var trip = Sensor.getSensorByName("Trip distance (stored in vehicle profile)");
   
  var last = trip.getValue();
  var current = last;
  
  var lastTime = Time.currentTimeMillis();
  var currentTime = lastTime;

  while (!quit) 
  {
    current = trip.getValue();
    currentTime = Time.currentTimeMillis();
      
    if (current < last)  last = trip.getValue();

    var dir = tripADir.getValue(); // tripADir undefined error
    
    if (dir == -1)
      tripA.setValue(tripA.getValue() - (current - last));
    else
      tripA.setValue(tripA.getValue() + (current - last));
      
    tripATime.setValue(tripATime.getValue() + ((currentTime - lastTime) / 1000));

    last = current;
    lastTime = currentTime;
      
    Time.sleep(1000);
      
  }
};
Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4
Page loaded in: 0.006 seconds.

  Follow me on twitter