0

I try to make several panel objects on my form in Cheat Engine using CE Lua script. How do this in the correct way?.

  local bricks = {}
  local brickWidth = 70
  local brickHeight = 25
  local brickRows  = 6
  local brickColumns  = 6

  local rleft = 5
  local rtop = 5
  local cleft = 5
  local ctop = 10

  for row = 0, brickRows do
   for column = 0, brickColumns do
   bricks[row] = createPanel(gameMain)
   bricks[row].Width = brickWidth
   bricks[row].Height = brickHeight
   bricks[row].Top = rtop
   bricks[row].Left = rleft
   bricks[row].Color = math.random(10,65255)
   rleft = rleft + brickWidth + 5
   bricks[column]  = createPanel(gameMain)
   bricks[column].Width = brickWidth
   bricks[column].Height = brickHeight
   bricks[column].Left = cleft
   bricks[column].Top = brickHeight + 5
   bricks[column].Color = math.random(10,65255)
   ctop = ctop + brickHeight + 5
   end
  end

But it fails. What I want is for each row and column will contain 6 panels. How to write the correct script?. Thank you

JoeFern
  • 117
  • 1
  • 8
  • Firstly lua arrays are starting by 1, also in this case you are running 7 times through the loop (-> `for row = 1, brickRows`). I actually don't understand what's your expected result, a 6x6-matrix? Or for each combination of rows and columns 12 panels? The problem in your code is, you overwrite the `bricks[row]`array with `bricks[column]`. Usually you want sth like `bricks[row][column]`. – csaar Jul 11 '19 at 07:15

1 Answers1

1

Create a table that will contain all bricks.

Create 1 table per row

Create and add 1 brick per column into each row

Simply use the loop counters to calculate the offsets.

Maybe you should solve such problems with pen and paper first.

local rows, cols = 6, 6
local width, height = 70, 25
local gap = 5

local bricks = {}

for row = 1, rows do
  bricks[row] = {}
  for col = 1, cols do
    local x = (col - 1) * (width + gap) -- x offset
    local y = (row - 1) * (height + gap) -- y offset
    local newBrick = createPanel(gameMain)
    -- assign brick's properties
    -- ...
    bricks[row][col] = newBrick
  end

end
Piglet
  • 27,501
  • 3
  • 20
  • 43