Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Description

MoveArray allows you move elements from an array to array.

The MoveArray has 5 parameters, one of which is optional.

...

pjs.moveArray() moves elements from and/or to an array. If padding is specified, it will clear out the remaining characters and elements in the target after the move is complete.

Parameters
  1. From array name
  2. Target array name
  3. From array index - 1 or higher, start from this index when working with the source.Target array name
  4. Target array index (as string, can be variable)  - 1 or higher, start from this index when working with the target.
  5. Padding (optional Boolean) - if passed in as true, the target will be padded. Can be null.

When moving an array, padding usually means it will clear out the remaining elements on the target after it does the moving. There is also no option to move right, it will always be move left.

Example
Example 1: array -> array
Code Block
languagejavascript
pjs.define("ARRX", { type: 'char', length: 5, dim: 5, initValue: 'Hi' });

...


pjs.define("ARRY", { type: 'char', length: 5, dim: 10, initValue: 'Test' });

...



pjs.MoveArray(

...

ARRX

...

, 

...

ARRY, 

...

1, 

...

1

...

, false);

...



return ARRY;

...


//'Hi 

...

  ','Hi  

...

 ','Hi 

...

  ','Hi 

...

  ','Hi 

...

  ','Test ','Test ','Test ','Test ','Test '
Example 2: char -> array
Code Block
languagejavascript
pjs.define("CHAR", { type: 'char', length: 5, initValue: 'Hello' });

...


pjs.define("ARRY", { type: 'char', length: 1, dim: 10 });

...



pjs.MoveArray(

...

CHAR

...

, 

...

ARRY, 

...

1, 

...

1

...

);

...



return ARRY;

...


//'H','e','l','l','o',' ',' ',' ',' ',' '

...

Example 3: array -> array (with source index)

In this example, we are moving ARRX into ARRY. Since the second parameter is 3, this means it will start the move from the 3rd element (skipping the first two) which results in only 3 elements being moved.

Code Block
languagejavascript
pjs.define("ARRX", { type: 'char', length: 5, dim: 5, initValue: 'Test' });

...


pjs.define("ARRY", { type: 'char', length: 5, dim: 10, initValue: '' });

...



pjs.MoveArray(

...

ARRX

...

, 

...

ARRY, 

...

3, "1");

...



return ARRY;

...


//

...

 '

...

Test ','

...

Test ','

...

Test ','   

...

 

...

 ',' 

...

   

...

 ',' 

...

   

...

 ','   

...

 

...

 ',' 

...

   

...

 ',' 

...

   

...

 ','   

...

 

...

 '
Example 4: array -> array (with target index)

This example shows a value of 6 on the 4th 2th parameter. Because the 4th 2th parameter indicates where the index is going to start on the target (ARRY), it's going to move elements into this array starting from the 6th element.

Code Block
languagejavascript
pjs.define("ARRX", { type: 'char', length: 5, dim: 5, initValue: 'ABCD' });

...


pjs.define("ARRY", { type: 'char', length: 5, dim: 10, initValue: 'EFGH' });

...



pjs.MoveArray(

...

ARRX

...

, 

...

ARRY, 

...

1, 

...

6

...

);

...



return ARRY;

...


//'EFGH ','EFGH ','EFGH ','EFGH ','EFGH ','ABCD ','ABCD ','ABCD ','ABCD ','ABCD '
Example 5: character const -> flags array

In this example, we're going to move a const ('111111') into flags, starting at element 71. This means elements 71, through to 76 in flags will be set to true. (since 1 is true, 0 would be false)

Code Block
languagejavascript
pjs.define("someInd", { type: 'boolean', initValue: true });

...



pjs.MoveArray(

...

'111111'

...

, 

...

flags, 

...

1, 

...

71

...

);

...



return flags[72];

...


//true
Example 6: array -> character field
Code Block
languagejavascript
pjs.define("ARRX", { type: 'char', length: 2, dim: 5, initValue: 'AB' });

...


pjs.define("CHAR", { type: 'char', length: 10 });

...



pjs.MoveArray(

...

ARRX

...

, 

...

CHAR, 

...

1, 

...

1

...

);

...



return CHAR;

...


//'ABABABABAB'


RPG Equivalent

MOVEA