Author Topic: Settings.remove doesn't remove  (Read 4318 times)

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Settings.remove doesn't remove
« on: 2007 September 26 14:33:45 »
I think this is a real bug, but it can perfectly be a misunderstanding on my side:

Code: [Select]
#include <pjsr/DataType.jsh>

var tmp;
Settings.write ("FOO/bar", DataType_UInt8, 42);
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
    console.writeln ("read 1 ok, tmp (",tmp,")");

Settings.remove ("FOO");
// this read should fail...
tmp = Settings.read ("FOO/bar", DataType_UInt8);
// ...thus, this conditional should be false
if (Settings.lastReadOK)
    console.writeln ("read 2 ok, tmp (",tmp,")");

Settings.remove ("FOO/bar");   // another try...
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
    console.writeln ("read 3 ok, tmp (",tmp,")");

Settings.remove ("FOO/*");   // and just another one
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
    console.writeln ("read 4 ok, tmp (",tmp,")");


Code: [Select]
Processing script file: /home/hue/foo.js
read 1 ok, tmp (42)
read 2 ok, tmp (null)
read 3 ok, tmp (null)
read 4 ok, tmp (null)
--
 David Serrano

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Settings.remove doesn't remove
« Reply #1 on: 2007 September 26 23:21:12 »
No bug here: Settings.lastReadOK is a method, not a property:

Code: [Select]
Boolean Settings.lastReadOK()

Thus, the result of a conditional construct such as:

Code: [Select]
if ( Settings.lastReadOK )

is always true, since indeed the Settings object has a lastReadOK item defined.

The correct code is:

Code: [Select]
if ( Settings.lastReadOK() )

Having said that, I realize that I made a design mistake because lastReadOK should be a read-only static property instead of a static method of Settings. This is the problem when one switches between C++ and JavaScript too quickly  :lol:

I think this problem should be corrected now that we don't have a lot of scripts out there using lastReadOK(), so how about turning this method into a property in the next release?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Settings.remove doesn't remove
« Reply #2 on: 2007 September 27 00:32:54 »
Quote from: "Juan Conejero"
so how about turning this method into a property in the next release?


Fine, no objections here.

I'm moving this thread to another, more appropriate place.
--
 David Serrano