of     1   

Wittiest
#183548413Sunday, February 14, 2016 1:07 AM GMT

Hi. So far I have created the following game: http://www.roblox.com/games/269177691/Unprecedented My goal is to make when people click a cube, they will see the squares it can move to be highlighted. What is the best way to make it where cubes can only move to vacant squares that are to the right of, to the left of, above, or below them? I can't think of any way to do this easily without making a huge database of where each piece can move from each spot.
cody123454321
#183548722Sunday, February 14, 2016 1:10 AM GMT

Record each object in the game and all obstructions. Each object and obstruction record has it's position. Iterate over those obstructions and check them to the surroundings of the object you want to move and determine it like that.
Wrathsong
#183548854Sunday, February 14, 2016 1:11 AM GMT

im not sure but is this supposed to be 3d checkers with blocks cause i like it
Wittiest
#183549096Sunday, February 14, 2016 1:14 AM GMT

No it is a new board game I am creating. I guess if I give each spot a coordinate and mark each blocks coordinate in a table it would work.
128Gigabytes
#183549216Sunday, February 14, 2016 1:15 AM GMT

Keep track of where pieces are in a table; Only use the parts to display the data the table contains. Don't use the parts as the data.
cheesecake123456
#183549507Sunday, February 14, 2016 1:18 AM GMT

Perhaps create a 2d array the size of the board and manoeuvre through that, you can then know the position of squares around the target point.
cody123454321
#183549630Sunday, February 14, 2016 1:19 AM GMT

He needs a 1D table. The actual position in the table of data is irrelevant.
Wittiest
#183550332Sunday, February 14, 2016 1:27 AM GMT

So this is what I am doing unless you guys meant something else that will work better: local gameBoard = { [a1] = "Red", [b1] = "Empty", [c1] = "Empty", [d1] = "Empty", [e1] = "Empty", [f1] = "Empty", [g1] = "Empty", [h1] = "Blue", [a2] = "Red", [b2] = "Empty", [c2] = "Empty", [d2] = "Empty", [e2] = "Empty", [f2] = "Empty", [g2] = "Empty", [h2] = "Blue", [a3] = "Red", [b3] = "Empty", [c3] = "Empty", [d3] = "Empty", [e3] = "Empty", [f3] = "Empty", [g3] = "Empty", [h3] = "Blue", [a4] = "Red", [b4] = "Empty", [c4] = "Empty", [d4] = "Empty", [e4] = "Empty", [f4] = "Empty", [g4] = "Empty", [h4] = "Blue", [a5] = "Red", [b5] = "Empty", [c5] = "Empty", [d5] = "Empty", [e5] = "Empty", [f5] = "Empty", [g5] = "Empty", [h5] = "Blue", [a6] = "Red", [b6] = "Empty", [c6] = "Empty", [d6] = "Empty", [e6] = "Empty", [f6] = "Empty", [g6] = "Empty", [h6] = "Blue", [a7] = "Red", [b7] = "Empty", [c7] = "Empty", [d7] = "Empty", [e7] = "Empty", [f7] = "Empty", [g7] = "Empty", [h7] = "Blue", [a8] = "Red", [b8] = "Empty", [c8] = "Empty", [d8] = "Empty", [e8] = "Empty", [f8] = "Empty", [g8] = "Empty", [h8] = "Blue" }
JarodOfOrbiter
#183552029Sunday, February 14, 2016 1:49 AM GMT

If you are doing that, PLEASE switch to a 2D table.
Wittiest
#183552814Sunday, February 14, 2016 1:59 AM GMT

So, I believe the following will work but I am not sure if you guys have a better way: ------Actual table to represent 1-8 and a-h----------- local gameBoard = { [a1] = "Crimson", [b1] = "Empty", [c1] = "Empty", [d1] = "Empty", [e1] = "Empty", [f1] = "Empty", [g1] = "Empty", [h1] = "Cyan", [a2] = "Crimson", [b2] = "Empty", [c2] = "Empty", [d2] = "Empty", [e2] = "Empty", [f2] = "Empty", [g2] = "Empty", [h2] = "Cyan", [a3] = "Crimson", [b3] = "Empty", [c3] = "Empty", [d3] = "Empty", [e3] = "Empty", [f3] = "Empty", [g3] = "Empty", [h3] = "Cyan", [a4] = "Crimson", [b4] = "Empty", [c4] = "Empty", [d4] = "Empty", [e4] = "Empty", [f4] = "Empty", [g4] = "Empty", [h4] = "Cyan", [a5] = "Crimson", [b5] = "Empty", [c5] = "Empty", [d5] = "Empty", [e5] = "Empty", [f5] = "Empty", [g5] = "Empty", [h5] = "Cyan", [a6] = "Crimson", [b6] = "Empty", [c6] = "Empty", [d6] = "Empty", [e6] = "Empty", [f6] = "Empty", [g6] = "Empty", [h6] = "Cyan", [a7] = "Crimson", [b7] = "Empty", [c7] = "Empty", [d7] = "Empty", [e7] = "Empty", [f7] = "Empty", [g7] = "Empty", [h7] = "Cyan", [a8] = "Crimson", [b8] = "Empty", [c8] = "Empty", [d8] = "Empty", [e8] = "Empty", [f8] = "Empty", [g8] = "Empty", [h8] = "Cyan" } function LettersNextTo(letter1,letter2) if letter1 == "a" and letter2 == "b" or letter2 == "a" and letter1 == "b" then return true elseif letter1 == "b" and letter2 == "c" or letter2 == "b" and letter1 == "c" then return true elseif letter1 == "c" and letter2 == "d" or letter2 == "c" and letter1 == "d" then return true elseif letter1 == "d" and letter2 == "e" or letter2 == "d" and letter1 == "e" then return true elseif letter1 == "e" and letter2 == "f" or letter2 == "e" and letter1 == "f" then return true elseif letter1 == "f" and letter2 == "g" or letter2 == "f" and letter1 == "g" then return true elseif letter1 == "g" and letter2 == "h" or letter2 == "h" and letter1 == "g" then return true end end function WhereCanIAttack(attacker,color) local ViableAttackSpots={} local ViableMoveSpots={} for place,occupied in pairs(gameBoard) do if (math.abs( tonumber(string.sub(place,2,2)) - tonumber(string.sub(attacker,2,2))) == 1) and LettersNextTo(string.sub(attacker,1,1),string.sub(place,1,1)) then if occupied~=color then return place end end end end
JarodOfOrbiter
#183553101Sunday, February 14, 2016 2:04 AM GMT

twoooo diimennnsiooonaaallll taaaabbbbllleeeesssss :c
Wittiest
#183553145Sunday, February 14, 2016 2:05 AM GMT

What do you mean by two dimensional tables? I am inexperienced. Does that mean setting it up with a loop or something?
JarodOfOrbiter
#183553247Sunday, February 14, 2016 2:06 AM GMT

Tables inside of tables: local Board = { {}, {}, {}, {} -- Each of the tables inside is a column, containing data. }
Wittiest
#183553444Sunday, February 14, 2016 2:09 AM GMT

Is this better? local gameBoard = {} for i=1,8 do gameBoard["a"..tostring(i)] = "Crimson" gameBoard["b"..tostring(i)] = "Empty" gameBoard["c"..tostring(i)] = "Empty" gameBoard["d"..tostring(i)] = "Empty" gameBoard["e"..tostring(i)] = "Empty" gameBoard["f"..tostring(i)] = "Empty" gameBoard["g"..tostring(i)] = "Empty" gameBoard["h"..tostring(i)] = "Cyan" end function LettersNextTo(letter1,letter2) if letter1 == "a" and letter2 == "b" or letter2 == "a" and letter1 == "b" then return true elseif letter1 == "b" and letter2 == "c" or letter2 == "b" and letter1 == "c" then return true elseif letter1 == "c" and letter2 == "d" or letter2 == "c" and letter1 == "d" then return true elseif letter1 == "d" and letter2 == "e" or letter2 == "d" and letter1 == "e" then return true elseif letter1 == "e" and letter2 == "f" or letter2 == "e" and letter1 == "f" then return true elseif letter1 == "f" and letter2 == "g" or letter2 == "f" and letter1 == "g" then return true elseif letter1 == "g" and letter2 == "h" or letter2 == "h" and letter1 == "g" then return true end end function WhereCanIAttack(attacker,color) local ViableAttackSpots={} local ViableMoveSpots={} for place,occupied in pairs(gameBoard) do if (math.abs( tonumber(string.sub(place,2,2)) - tonumber(string.sub(attacker,2,2))) == 1) and LettersNextTo(string.sub(attacker,1,1),string.sub(place,1,1)) then if occupied~=color then return place end end end end
cody123454321
#183624966Sunday, February 14, 2016 11:49 PM GMT

Use numbers and objects to represent this data before I throw up.

    of     1