Shop OBEX P1 Docs P2 Docs Learn Events
TRUE or FALSE? — Parallax Forums

TRUE or FALSE?

idbruceidbruce Posts: 6,197
edited 2011-01-29 18:27 in Propeller 1
lllllllllllllll

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-01-29 06:26
    Expose the value through a getter or a pointer to HUB memory.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-29 06:55
    IF child.method(parameter) == TRUE
    or
    IF child.method(parameter) == FALSE
    or
    IF child.method(parameter)
    or
    IFNOT child.method(parameter)
    or
    any of a variety of ways ... all valid

    You must be doing something wrong to get an incorrect comparison. Show your code rather than 'I did this and it didn't work'. It would save a lot of time and effort. There's no specific 'proper way'. These are Boolean expressions with FALSE being zero and TRUE being non-zero just like in C++.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-01-29 07:12
    Hello Mike,

    you have a very good style to bring things to the point. Clear and short. I like this way.

    So I gave myself a new target: write postings clear and short.
    Thank you for initiating this.

    best regards

    Stefan
  • Mike GMike G Posts: 2,702
    edited 2011-01-29 07:13
    @idbruce, the attached example comes directly from the propeller manual. From my experience, C/C++ constructs are very similar to SPIN at least in this example.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-01-29 07:52
    Bruce,

    FALSE has a value of zero -- that's the case for both Spin and C/C++. A non-zero value is generally treated as TRUE in most case. However, if you're testing specifically for the value of TRUE, then this is different between Spin and C/C++. TRUE has a value of 1 in C/C++ and $ffffffff in Spin.

    Dave
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-29 08:49
    In some code I have forced the return value to match Spin's true and false constants by doing this
    return (resultvalue <> 0)
    

    If the return value is non-zero (true) it will be promoted to $FFFFFFFF which matches Spin's constant value for true. This ensures that code like this:
    if object.method() == true
    

    will work. Spin will promote non-zero to true if you leave out the equality test:
    if object.method()
        ' return was true
    

    Of course, if you want to write code that will work and is absolutely clear you could always test for false instead
    if object.method() <> false
    

    ... though this is a negative test, and sometimes just doesn't 'feel' right.
  • idbruceidbruce Posts: 6,197
    edited 2011-01-29 17:36
    First off, thank you for all the replies

    @Mike - Excerpts are shown below.
    PUB IsNewDataAvailable
      RETURN NewDataAvailable
    

    IF Slave.IsNewDataAvailable == TRUE

    @Dave - In C++ I never had any trouble comparing boolean function return values. Return TRUE or FALSE and compare to TRUE or FALSE

    @Jon - That was very interesting.
    In some code I have forced the return value to match Spin's true and false constants by doing this

    That's what I want.

    Thanks guys

    Bruce
  • kuronekokuroneko Posts: 3,623
    edited 2011-01-29 17:58
    PUB IsNewDataAvailable
      RETURN NewDataAvailable
    
    This particular method suffers from NewDataAvailable being a byte rather than a long (last time I checked). While it doesn't matter for FALSE it does for TRUE as JonnyMac pointed out ($FF vs $FFFFFFF).
  • idbruceidbruce Posts: 6,197
    edited 2011-01-29 18:02
    Marko

    Thanks for the tip, it is now a long. I am having problems getting this simulation going. :(

    Still working on it though. Getting it working should be right around the corner.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-01-29 18:12
    Marko

    If you are still listening....
    PUB GetDataFields(DataField1Pointer, DataField2Pointer)
      'This method can only be called once by the
      'parent object, and then DataField1 and DataField2
      'are set to zero.
    '  LONGMOVE(DataField1Pointer, @DataField1, 1)
    '  LONGMOVE(DataField2Pointer, @DataField2, 1)
      LONG[DataField1Pointer] := DataField1
      LONG[DataField2Pointer] := DataField2
    '  SetDataFieldsToZero
    '  NewDataAvailable := FALSE
    

    Keeps returning values of zero with only one write and one read ARRRG
  • kuronekokuroneko Posts: 3,623
    edited 2011-01-29 18:18
    The last version of this object (from the other thread) doesn't set any return value for this method, so it's always 0. Can you elaborate?
  • Mike GMike G Posts: 2,702
    edited 2011-01-29 18:23
    I'm rather confused here... This thread is about using an object from the OBEX?
  • idbruceidbruce Posts: 6,197
    edited 2011-01-29 18:26
    Marko

    In the method ReceiveDataWithCRC there is the following call ParseReceivedData(@MessageBuffer, @DataField1, @DataField2), ParseReceivedData seperates the message buffer at the colon delimiter creating two decimal values and assigning the values to DataField1 and DataField2. Retrieval of these values are attempted in the parent with the following call:

    Slave.GetDataFields(@DataField1, @DataField2)
  • idbruceidbruce Posts: 6,197
    edited 2011-01-29 18:27
    Mike G

    Sorry for that, my fault, got sidetracked.

    Bruce
Sign In or Register to comment.