Advertisement
ZoriaRPG

ZScript Scope Workshop / Tutorial

Jun 3rd, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.45 KB | None | 0 0
  1.  
  2. Where did you put them in your script file?
  3.  
  4. They should be either at the file scope,  or inside the scrito scope and outside of the run() function.
  5.  
  6. [code]
  7. import "std.zh"
  8.  
  9. //This is the File Scope
  10. //Functions placed at this scope are available globally by calling their identifier:
  11.  
  12. // if ( IsLinkFacingSolid() )
  13.  
  14.  
  15. //Returns true if Link is facing a solid, on-screen combo.
  16. bool IsLinkFacingSolid(){
  17.     int a; int dir = Link->Dir; int cmb = ComboAt(Link->X, Link->Y);
  18.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  19.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  20.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  21.     if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  22.     if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  23.     if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return false; //if the left columb
  24.     if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return false; //if the right column
  25.     if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return false; //if the top row
  26.     if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return false; //if the bottom row
  27.     if ( cmb >= 0 && cmb <= 176 ) a = cmb + combooffsets[dir];
  28.     else a = -1;
  29.     if ( a != -1 ) {
  30.         return ( Screen->isSolid(ComboX(a), ComboY(a)));
  31.     }
  32.     return false;
  33. }
  34.  
  35. //Returns true if Link is facing a solid, on-screen combo, but allows specifying a default return.
  36. bool IsLinkFacingSolid(bool default_return){
  37.     int a; int dir = Link->Dir; int cmb = ComboAt(Link->X, Link->Y);
  38.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  39.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  40.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  41.     if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  42.     if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  43.     if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return default_return; //if the left columb
  44.     if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return default_return; //if the right column
  45.     if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return default_return; //if the top row
  46.     if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return default_return; //if the bottom row
  47.     if ( cmb >= 0 && cmb <= 176 ) a = cmb + combooffsets[dir];
  48.     else a = -1;
  49.     if ( a != -1 ) {
  50.         return ( Screen->isSolid(ComboX(a), ComboY(a)) );
  51.     }
  52.     return default_return;
  53. }
  54.  
  55. ///////////////////////////////////////////////////
  56. /// Example of Script-pScope Function Placement ///
  57. ///////////////////////////////////////////////////
  58.  
  59. //If you place the functions at a script scope, they are available to that sacript by calling their identifier,
  60. //or externally by calling the script name then a dot, then the identifier.
  61.  
  62. ffc script foo{
  63.     void run(){
  64.         while ( IsLinkFacingSolid() ) { Waitframe() };
  65.     }
  66.     //script scope
  67.    
  68.    
  69.     //Returns true if Link is facing a solid, on-screen combo.
  70.     bool IsLinkFacingSolid(){
  71.         int a; int dir = Link->Dir; int cmb = ComboAt(Link->X, Link->Y);
  72.         int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  73.         if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  74.         if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  75.         if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  76.         if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  77.         if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return false; //if the left columb
  78.         if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return false; //if the right column
  79.         if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return false; //if the top row
  80.         if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return false; //if the bottom row
  81.         if ( cmb >= 0 && cmb <= 176 ) a = cmb + combooffsets[dir];
  82.         else a = -1;
  83.         if ( a != -1 ) {
  84.             return ( Screen->isSolid(ComboX(a), ComboY(a)));
  85.         }
  86.         return false;
  87.     }
  88.  
  89.     //Returns true if Link is facing a solid, on-screen combo, but allows specifying a default return.
  90.     bool IsLinkFacingSolid(bool default_return){
  91.         int a; int dir = Link->Dir; int cmb = ComboAt(Link->X, Link->Y);
  92.         int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  93.         if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  94.         if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  95.         if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  96.         if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  97.         if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return default_return; //if the left columb
  98.         if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return default_return; //if the right column
  99.         if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return default_return; //if the top row
  100.         if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return default_return; //if the bottom row
  101.         if ( cmb >= 0 && cmb <= 176 ) a = cmb + combooffsets[dir];
  102.         else a = -1;
  103.         if ( a != -1 ) {
  104.             return ( Screen->isSolid(ComboX(a), ComboY(a)) );
  105.         }
  106.         return default_return;
  107.     }
  108. }
  109.  
  110. //This is how you call a function of a script.
  111.  
  112. ffc script bar{
  113.     void run(){
  114.         while ( foo.IsLinkFacingSolid() ) {
  115.             //script name ( dot ) function_identifier()
  116.             Waitframe();
  117.         }
  118.     }
  119. }
  120.  
  121. //YOu cannot have identically named global (file scope) and local (script scope) functions, but you /can/ have
  122. //identically named SCRiPT-scope functions, so..
  123.  
  124. ffc script fum{
  125.     void run(){
  126.         while ( IsLinkFacingSolid() ) { Waitframe(); }
  127.     }
  128.     bool IsLinkFacingSolid(){
  129.         int a; int dir = Link->Dir; int cmb = ComboAt(Link->X, Link->Y);
  130.         int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  131.         if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  132.         if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  133.         if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  134.         if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  135.         if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return false; //if the left columb
  136.         if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return false; //if the right column
  137.         if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return false; //if the top row
  138.         if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return false; //if the bottom row
  139.         if ( cmb >= 0 && cmb <= 176 ) a = cmb + combooffsets[dir];
  140.         else a = -1;
  141.         if ( a != -1 ) {
  142.             return ( Screen->isSolid(ComboX(a), ComboY(a)));
  143.         }
  144.         return false;
  145.     }
  146. }
  147.  
  148. //This script will compile with scripts foo and bar, if and only if you do not declare IsLinkFacingSolid()
  149. //at a file (global) scope.
  150.  
  151. //It is up to you to decide which format you want to follow. If you feel that you may need minor variations
  152. //of a function using the same identifier, such as GetValue() per script, then you put them at the script scope.
  153.  
  154. //If the function isn;t likely to change, placing it at a global scope is the best option.
  155.  
  156. //Script cope Perks
  157.  
  158. //Here is a small workshop on script scope functions
  159.  
  160. ffc script data_one{
  161.     void run(){
  162.    
  163.     }
  164.     int Get(int index){
  165.         int arr[10] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29};
  166.         return arr[index];
  167.     }
  168. }
  169.  
  170. ffc script data_two{
  171.     void run(){
  172.    
  173.     }
  174.     int Get(int index){
  175.         int arr[10] = {99, 98, 97, 96, 95, 94, 93, 93, 91, 90};
  176.         return arr[index];
  177.     }
  178. }
  179.  
  180. ffc script get_data{
  181.     void run(int dataset){
  182.         int dat[10];
  183.         if ( dataset == 1 ) {
  184.             for ( int q = 0; q < 10; q++ ) {
  185.                 dat[q] = data_one.Get(q); //populate the array with the values in the Get function
  186.                             //of script data_one.
  187.             }
  188.         }
  189.         if ( dataset == 2 ) {
  190.             for ( int q = 0; q < 10; q++ ) {
  191.                 dat[q] = data_two.Get(q);//populate the array with the values in the Get function
  192.                             //of script data_two.
  193.             }
  194.         }
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement