Shop OBEX P1 Docs P2 Docs Learn Events
Spin Syntax Question... — Parallax Forums

Spin Syntax Question...

jmspaggijmspaggi Posts: 629
edited 2010-08-30 10:11 in Propeller 1
Hi all,

I'm sure there is a super clean do to what I'm looking for...

Here is the code
bytemove (lf_number_addr+index, @sd_buffer+cursor, strsize(@sd_buffer+cursor)+1)

What I want to do is to transfert only a certain amount for memory. if strsize(@sd_buffer+cursor)+1 is bigger than 30, I want to limit it to 30. I can put a if before, but is there another way to do something like
bytemove (lf_number_addr+index, @sd_buffer+cursor, strsize(@sd_buffer+cursor)+1>30?30:strsize(@sd_buffer+cursor)+1)

This is Java syntax. Not sure for Spin...

Thanks,

JM

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 10:05
    There is no equivalent to the "? :" operator. In your case, you're just doing a maximum calculation and there is an operator for that situation. Check out the description for the "<#" operator in the Propeller Manual.

    You could use something like: (strsize(@s)+1)<#30
  • jmspaggijmspaggi Posts: 629
    edited 2010-08-30 10:11
    Super, thanks a lot! That's exactly what I was looking for. Even beter than the ? syntax for this situation ;)

    JM

    Page 155 of the manual:
    Limit Maximum ‘<#’, ‘<#=’
    The Limit Maximum operator compares two values and returns the lowest value. Limit Maximum can be used in both variable and constant expressions. Example:
    X := Y + 21 <# 250
    The above example adds 21 to Y and limits the result to a maximum value to 250. If Y is 200 then 200 + 21 = 221; it is less than 250 so X is set to 221. If Y is 240 then 240 + 21 = 261; it is greater than 250 so X is set to 250 instead.
    Limit Maximum has an assignment form, <#=, that uses the variable to its left as both the first operand and the result destination. For example,
    X <#= 50 'Short form of X := X <# 50
    Here, the value of X is limited to a maximum value of 50 and the result is stored back in X. The assignment form of Limit Minimum may also be used within expressions for intermediate results; see Intermediate Assignments, page 147
    
Sign In or Register to comment.