daily pastebin goal
45%
SHARE
TWEET

Array Write/Read Functions (Sebastian Nigro)

a guest Jan 17th, 2016 171 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// array_write(variable,char)
  2.  
  3. /*
  4.     Writes the array as a string with 'char' as a spacer for
  5.     parsing the string back into the program later.
  6. */
  7.  
  8. var length = array_length_1d(argument0);
  9. var array = argument0;
  10. var str = "";
  11.  
  12. str = string(array[@ 0]);
  13.  
  14. if ( length > 1 )
  15. {
  16.     for(var i = 1; i < length; i ++ )
  17.     {
  18.         str = str+argument1+string(array[@ i]);
  19.     }
  20. }
  21.  
  22. return str
  23.  
  24. ------------------------------------------------------------------------------------------------------------------------------------------
  25.  
  26. /// array_read(variable,char)
  27.  
  28. /*
  29.     Reads the string back into an array.
  30. */
  31.  
  32. var str_temp = argument0;
  33. var str1 = "";var str2 = "";
  34. var array = 0;var temp = "";
  35. var index = 0;
  36.  
  37. for(var i = 1; i <= string_length(str_temp); i ++)
  38. {
  39.     str1 = string_char_at(str_temp,i);
  40.     str2 = str2 + str1;
  41.     if ( str1 == argument1 )
  42.     {
  43.         // This bit allows us to store variables as reals instead of strings where possible to avoid using the real() function later
  44.         temp = string(string_copy(str_temp,i-real(string_length(str2))+1,real(string_length(str2))-1));str2="";
  45.         if ( string_digits(temp) != "" )
  46.         {
  47.             array[index] = real(temp);
  48.             index ++;
  49.         }
  50.         else
  51.         {
  52.             array[index] = temp;
  53.             index ++;
  54.         }
  55.     }
  56.     if ( i == string_length(str_temp) )
  57.     {
  58.         temp = string(string_copy(str_temp,i-real(string_length(str2))+1,real(string_length(str2))));str2="";
  59.         if ( string_digits(temp) != "" )
  60.         {
  61.             array[index] = real(temp);
  62.             index ++;
  63.         }
  64.         else
  65.         {
  66.             array[index] = temp;
  67.             index ++;
  68.         }
  69.     }
  70. }
  71.  
  72. return array
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top