Home AMX User Forum NetLinx Studio

array problem

I have a problem with doing an array of integer.
I declared the array:
INTEGER CODE [4]
And I want that if code[index] is null, insert a number. And after the array is full I want to send something and then I want to clear the array.
How can I check if the array is null? And how can I clear the array?
Thanks for any help that leads me in the right direction. Examples are very much appreciated

Comments

  • jjamesjjames Posts: 2,908
    udi wrote: »
    I have a problem with doing an array of integer.
    I declared the array:
    INTEGER CODE [4]
    And I want that if code[index] is null, insert a number. And after the array is full I want to send something and then I want to clear the array.
    How can I check if the array is null? And how can I clear the array?
    Thanks for any help that leads me in the right direction. Examples are very much appreciated
    // Check to see if null
    if(!code[index]) // or if(code[index] == 0)
    {
      code[index] = someNumber
    }
    
    // Clear the array
    for(i=1;i<=length_array(code);i++)
    {
       code[i] = 0;
    }
    
  • a_riot42a_riot42 Posts: 1,624
    udi wrote: »
    I have a problem with doing an array of integer.
    I declared the array:
    INTEGER CODE [4]
    And I want that if code[index] is null, insert a number. And after the array is full I want to send something and then I want to clear the array.
    How can I check if the array is null? And how can I clear the array?
    Thanks for any help that leads me in the right direction. Examples are very much appreciated

    code[index] can't really be null. At initialization it will be equal to 0 until modified to some other value. If 0 is a valid number then checking to see if its 0 won't tell you if its been made equal to 0 or is still 0 from initialization.
    Paul
  • viningvining Posts: 4,368
    Doesn't null == 0 ($00)?
    CHR HEX DEC
    nul...00....0
    I think what Paul means is if you want to initialize a var to a value that will never be assigned to that var during the normal operation of the code you first have to determine the range of possible values that can be assigned during normal operations. If the normal assigned values ranges from 1-10 then initializing to 0 is ok but if normal assigned values can range from 0-10 then intialze to 11 or some other value like $FF for instance might be what's required. If the value that may be assigned during normal operation of the code can span the full integer range from 0-65536 then maybe create a sinteger and initialize it with a negative number so that any positive number will have been the result of the program and not confused with the initialization process.
  • a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    Doesn't null == 0 ($00)?

    Depends on how you want to define it. I think of the control character as nul, and null is no value, not even 0.
    vining wrote: »
    If the value that may be assigned during normal operation of the code can span the full integer range from 0-65536 then maybe create a sinteger and initialize it with a negative number so that any positive number will have been the result of the program and not confused with the initialization process.

    That works and is what I end up doing if I need to do some math on the values. If its just being stored to send off as a command I will use characters rather than integers. That way you can use the integer 0 as nul and don't have to deal with sintegers.

    ie:
    char CODE [4]

    CODE[1] = 0 // no value received
    CODE[1] = '0' // contains the value of ascii zero

    It also makes 'clearing' the array a little simpler without needing a for loop.
    CODE = "$00,$00,$00,$00"

    Paul
  • udiudi Posts: 107
    THANKS FOR THE HELP.
  • DHawthorneDHawthorne Posts: 4,584
    vining wrote: »
    Doesn't null == 0 ($00)?

    For all intents in NetLinx it does, since NetLinx initializes numeric variables to 0. Many programming languages do not though, and it means nothing has been assigned ... so if you try using it, you wind up with whatever value was sitting at that memory address. That's how those "null pointer" exploits work, they finagle a way to access memory they shouldn't be able to.
Sign In or Register to comment.