Board Game Project: Drag and Drop in Lua for Corona SDK

@develephant

After reading this and encountering a few more problems, I have some more questions.  First of all, when I use a variable in a function like:

local function placePiece( Piece, x, y )

 if canPlacePiece( Piece ) then
  Piece.x = x
  Piece.y = y
 end

end

I am used to Java, where the piece’s x and y would not change, does this change the x and y?

Also, I am wondering about classes in Lua.  Are they traditional classes or just lists of info? Can I create an instant of the class.  I tried to create two pieces with the Piece:new method and when one began to affect another.

@develephant,

disregard my comment above referring to declaring a function format, it is not correct.

The function format “local testFunction3 = function()” cannot be called from within the same function. 

kdog’s formatting of his function declaration’s are fine as is.

@kdog
I’m guessing since I don’t know what your current code is, I still
believe your basic problem is you are not spawning into an indexed
table, your Piece’s have no index reference to identify them so when you drag one, the other may move for instance.

kdog wrote:

I am used to Java, where the piece’s x and y would not change, does this change the x and y?


yes, your function changed the x,y to the param values of x,y.

Nail

@kdog I have actually just ran into a similar issue with the properties being updated on one instance affecting another.  I’m still researching it and will post back my results.

This article demonstrates one possible “class” style framework:

http://www.develephant.net/an-rpg-themed-oop-design-pattern-for-corona-sdk-part-1/

Lua is able to be morphed into many types of coding styles, this is a great things at times, but coming from more structured languages like Java, it may seem counter-intuitive at first.

I’d like to see the finished code on this one kdog!

Just learning Corona and need to make a flat 2 dimensional game board with movable pieces.

I’d like to see the finished code on this one kdog!

Just learning Corona and need to make a flat 2 dimensional game board with movable pieces.