User Tools

Site Tools


grid:api

Grid API

This section explains the basic grid interaction and the building block of function you can use.

Battler Position

Battler position is represented as an index in a one-dimension array (Yes, even though the grid actually has two dimensions of X and Y). For technical reasons, this was to simplify the implementation.

i.imgur.com_5ts4ncw.jpg

Grid dimension

To determine the dimension the grid, set it in the API section of then script.

MaxRow = 3  # Determine the maximum row
MaxCol = 8  # Determine the maximum column

When you decide the dimension of the grid, the maximum index is changed accordingly. i.e, if you put the dimension as 8×3 for width and height respectively, the maximum index is 23 resulted from 8 multiplied by 3 minus 1 (Because array started from index 0). And the script will automatically recognize the index 0 to 7 as the first row, 8 to 15 as the second row, and 16 to 23 as the last row.

Because the position is stored in a one-dimension array, so does the battler position. To determine the position, you have to make a nested array that represents the screen position of that said index. For example, this is the position setting in the 640×360 screen in the sample game.

Position = 
[
[134,158],[182,158],[240,158],[292,158],[346,158],[400,158],[454,158],[508,158],
[124,180],[180,180],[236,180],[292,180],[348,180],[404,180],[460,180],[516,180],
[105,200],[164,200],[226,200],[288,200],[350,200],[412,200],[474,200],[536,200],
]

The first index represents 134 for the x-axis position and 158 as the y-axis position. Do note that the script will NOT care about how you actually put the screen position. Make sure that the grid position correctly represents the position. You can always the ShowIndex = true to enable the index display in Grid - Display Grid Index section, so that you could see the index position like in the screenshot provided above.

Remember when setting the position, the script will always treat the first index (which is index 0) to be always on the top left of the screen. You can not change this behavior unless you internally change how the module works. Fortunately, the end-user will not know this behavior, this is just how the back-end system works.

Getting Position

Getting the position is largely used in the targeting system and you're expected to know how to code ruby. Here are the list of important functions to be used (in the script call).

Neighbor direction

Grid.neighbor(index, direction, {times})

This function gets the neighbor/adjacent position of the current grid.

  • Index = Represents which index you want to get its neighbor position
  • Direction = Represents which direction you want to check in a Numeric Keypad. Which 2 represent for down, 4 for left, 6 for right, etc. You can use the diagonal as well.
  • Times = Optional parameter that can be omitted. The parameter function as to how far you want to check into that direction (The default value is 1).

Here is a list of examples. The orange cell represents the center grid you want to check its neighbor

Grid.neighbor(13, 4)  # Return value = 12
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
  Grid.neighbor(13, 4, 2)  # Return value = 11
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
Grid.neighbor(5, 8)  # Return value = nil
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23

Because the direction up does not have a grid position, it will return nil

Linear direction

Grid.linear(index, direction, {times})

This function is to get an array that represents a linear direction.

  • Index = Represents which index you want to get its neighbor position
  • Direction = Represents which direction you want to check in a Numeric keypad. Unlike checking the neighbor position, the direction parameter here must be inputted as an array. i.e, it looks like this [2,4,6,8] so you can get multiple directions at the same time.
  • Times = Optional parameter, it checks how far you want it to be. If omitted, it will have the default value is 1. But why would you omit it?

Here is a list of examples. The orange cell represents the center grid you want to check its linear path.

Grid.linear(13, [4], 4)  # Return value = [12, 11, 10, 9]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
  Grid.linear(22, [4,6,8], 3)  # Return value = [6, 14, 19, 20, 23]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
  Grid.linear(22, [4,7,8], 3)  # Return value = [4, 6, 13, 14, 19, 20]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23

Surrounding direction

Grid.surrounding(index, direction)

This function is to get an array that represents the adjacent grid. This is basically like the Grid.linear function but with the times parameter omitted. Here are the examples

Grid.surrounding(13, [1,2,3,4,6,7,8,9])  # Return [4, 5, 6, 12, 14, 20, 21, 22]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
  Grid.surrounding(13, [2,4,6,8])  # Return [5, 12, 14, 21]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
  Grid.surrounding(7, [1,2,3,4,6,7,8,9])  # Return [6, 14, 15]
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23

Combining the direction

Combining the functions is an essential part of the system. The targeting and area of effect are largely depending on how creative you're to combine these functions.

Supposed that we're going to replicate this. With red being the initial index, orange being the epicenter, then light green as the area of effect (plus the epicenter).

0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23

The code can go like this.

  epicenter = Grid.neighbor(14, 4, 4)
  result = [epicenter] + Grid.linear(epicenter, [2,4,6,8], 2)
  result += Grid.surrounding(epicenter, [1,3,7,9])
  return result

It will yield an array with the value as [1, 2, 3, 8, 9, 10, 11, 12, 17, 18, 19]. Note that in this particular example, the source index is hardcoded to 14. However, it can also be replaced with many things like the user position or the @center_grid as explained in the targeting system

Other Functions

This section is under construction and may be completed later 
once the system is released
grid/api.txt · Last modified: 2019/12/29 09:42 by theoallen