It can not change the global variable is initialized in the same lua file, but only when you start the gameError: map.lua:14: attempt to perform arithmetic on global 'mapPosX' (a nil value)
map.lua
Code: Select all
function initMap()
mapShow = false
mapPosX = -80;
mapPosY = -50;
colorChanged = false;
end
function drawMap()
lg.draw(gameMap, gameMapQuad, mapPosX, mapPosY);
lg.draw(gameMapView, gameMapQuad, mapPosX, mapPosY);
end
function moveMap(X,Y)
nextPosX = mapPosX+X; --Then an error occurs
nextPosY = mapPosY+Y; -- Here, too, there is an error
dx = 0;
dy = 0;
r, g, b, a = gameMapData:getPixel(windowWidth/2-nextPosX+dx,windowHeight/2-nextPosY+dy);
if a >= 50 then
mapPosX = nexpPosX;
mapPosY = nextPosY;
else
r, g, b, a = gameMapData:getPixel(windowWidth/2-nextPosX+dx,windowHeight/2-mapPosY+dy)
if a >= 50 then
mapPosX = nextPosX;
end
r, g, b, a = gameMapData:getPixel(windowWidth/2-mapPosX+dx,windowHeight/2-nextPosY+dy)
if a >= 50 then
mapPosY = nextPosY;
end
end
end