is it possible to know this value ?

hi,

i’m searching a way to know the value of a variable.

to begin i know that :

character.x = 200 character.x = gridGame[2][3]

what i would do is this :

character.x = 200 character.x = gridGame[ax][ay]

and know that :

ax=2 ay=3

with the position.x how to know the ax and ay value ?

how to do this ?

thanks

the objective is to know the coordinate to move my character on the grid. a the moment it goes well with some problems. if i know the ax and ay value it could resolve my problem.

So for a given X value what is the grid position?

Say your grid is made up of 20 pixel squares, which start at 0, 0:

[lua]

local gridXStart = 0

local gridYStart = 0

local gridXSize = 20

local gridYSize = 20

local getGridPosition (obj)

  local ax = (math.floor(obj.x - gridXStart) / gridXSize)

  local ay = (math.floor(obj.y - gridYStart) / gridYSize)

  return ax, ay

end

local testX, testY = getGridPosition (character)

print ("CHARACTER IS AT GRID POSITION “…testX…”, "…testY

[/lua]

thanks a lot it works

obj = display.newCircle( 100, 100, 30 ) obj.x=100 obj.y=6 local gridXStart = 0 local gridYStart = 0 local gridXSize = 20 local gridYSize = 20     local function getGridPosition (obj)     ax=math.floor((obj.x - gridXStart) / gridXSize)   ay=math.floor((obj.y - gridYStart) / gridYSize)     return ax, ay   end     local testX, testY = getGridPosition (obj)   print ("CHARACTER IS AT GRID POSITION "..testX..", "..testY)

So for a given X value what is the grid position?

Say your grid is made up of 20 pixel squares, which start at 0, 0:

[lua]

local gridXStart = 0

local gridYStart = 0

local gridXSize = 20

local gridYSize = 20

local getGridPosition (obj)

  local ax = (math.floor(obj.x - gridXStart) / gridXSize)

  local ay = (math.floor(obj.y - gridYStart) / gridYSize)

  return ax, ay

end

local testX, testY = getGridPosition (character)

print ("CHARACTER IS AT GRID POSITION “…testX…”, "…testY

[/lua]

thanks a lot it works

obj = display.newCircle( 100, 100, 30 ) obj.x=100 obj.y=6 local gridXStart = 0 local gridYStart = 0 local gridXSize = 20 local gridYSize = 20     local function getGridPosition (obj)     ax=math.floor((obj.x - gridXStart) / gridXSize)   ay=math.floor((obj.y - gridYStart) / gridYSize)     return ax, ay   end     local testX, testY = getGridPosition (obj)   print ("CHARACTER IS AT GRID POSITION "..testX..", "..testY)