Notice: Constant DATE_RFC7231 already defined in /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc on line 258
Arrays | ComScript Manual

Error message

  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 690 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 691 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 692 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 695 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 697 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in include_once() (line 290 of /home2/greeneye/public_html/comscript_manual/sites/default/settings.php).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in include_once() (line 291 of /home2/greeneye/public_html/comscript_manual/sites/default/settings.php).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in include_once() (line 299 of /home2/greeneye/public_html/comscript_manual/sites/default/settings.php).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in include_once() (line 306 of /home2/greeneye/public_html/comscript_manual/sites/default/settings.php).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_settings_initialize() (line 860 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in drupal_settings_initialize() (line 869 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: session_name(): Cannot change session name when headers already sent in drupal_settings_initialize() (line 872 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc:258) in _drupal_bootstrap_page_cache() (line 2485 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: session_set_save_handler(): Cannot change save handler when headers already sent in drupal_session_initialize() (line 242 of /home2/greeneye/public_html/comscript_manual/includes/session.inc).
  • Warning: session_id(): Cannot change session id when headers already sent in drupal_session_initialize() (line 266 of /home2/greeneye/public_html/comscript_manual/includes/session.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc:258) in drupal_send_headers() (line 1305 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc:258) in drupal_send_headers() (line 1305 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in book_prev() (line 775 of /home2/greeneye/public_html/comscript_manual/modules/book/book.module).
  • Warning: Cannot modify header information - headers already sent by (output started at /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc:258) in drupal_send_headers() (line 1305 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Warning: Cannot modify header information - headers already sent by (output started at /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc:258) in drupal_send_headers() (line 1305 of /home2/greeneye/public_html/comscript_manual/includes/bootstrap.inc).
  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home2/greeneye/public_html/comscript_manual/includes/common.inc).

Arrays

 

Arrays are essentially just list of data, much like a column a values in a spread sheet.  In ComScript (and most languages) an array has a name (e.g. my array) and a index that refers to the location or address of the value stored in the array.  Staying with the spreadsheet analogy, the name of the array would equate to the column header or description in the first row and the index would be the row number.  Let's look a the example data below.

Name    TestScore
Jim        89
Jane      100
Joe        67
Betty     92
Fred     96
 
The above data could be easily loaded into two (parallel) arrays, Name and TestScore.  In more complicated languages, arrays indexes begin with 0, but ComScript lets you index your array to any number, although we suggest 0 or 1 so it's easier to follow.  Here, we could assign "Jim" to array Name at position 1.  A simple way to do that in ComScript would be: <set var="Name@1" value="Jim" /> and then <set var="TestScore@1" value="89" />.  The @ symbol tells ComScript that this variable is an array and it position follows the @ symbol.  You could assign all of the above names and scores with individual set commands or, if the data was in a file, you could read in each line and parse the data into array variables inside a readfile loop.
 
Lets assume that the name and score lists above are written in a file called MathTest1.txt.  The following code would load the two column headers, and all the names and scores into two arrays.
 
<set var="i" value="0" /> <!-- initialize readfile loop counter and array index to 0 -->
<!-- read individual lines from MathTest1.txt into DataLine until the end of the file -->
<readfile var="DataLine" file="MathTest1.txt" >
    <!-- Parse each DataLine into the array variables -->
    <loadvars string="[DataLine]" vars="Name@[i],TestScore@[i]" type="string" delimiter=" " multi="True" />
    <math var="i" expression="[i]+1" /> <!-- increment loop counter/index -->
</readfile>
 
<set var="j" value="0" /> <!-- initialize write loop counter and array index to 0 -->
<while expression="[j] LT [i]" > <!-- stops at the number of lines read above -->
   <!-- write out array variables, MathTest1out.txt will the same as MathTest1.txt, but the name and score
           will be comma separated -->
   <write file="MathTest1out.txt" string="[Name@[j]],[TestScore@[j]]{10}{13}" />
   <math var="j" expression="[j]+1" /> <!-- increment loop counter/index -->
</while>
 
Notice that when referencing array variables in the write command above that both the array name and the index are in brackets and the index is also in brackets (e.g. [Name@[j]]).  If not using a literal value for the index no square brackets are required (e.g. [Name@1]). 
 
Be sure to look at the "ArrayTest" profile example include in the ComScript download.