Hey,
Screenshot: http://screencast.com/t/k6NjRksfo
That’s the error I started getting. I’m not sure what changed to cause that - just painting my map with tiles.
Hey,
Screenshot: http://screencast.com/t/k6NjRksfo
That’s the error I started getting. I’m not sure what changed to cause that - just painting my map with tiles.
This is usually a scope issue
If you could post your main.lua code that would be helpful. The terminal error itself doesn’t tell me much.
display.setStatusBar( display.HiddenStatusBar )
system.activate( “multitouch” )
display.setDefault( “magTextureFilter”, “nearest” )
display.setDefault( “minTextureFilter”, “nearest” )
–Load up MTE
local mte = require “MTE.mte”
local json = require “json”
–Message Box–
local msgbox
msgbox = display.newText(“null”, 60, 130, native.systemFont, size)
msgbox:setTextColor(255, 0, 0)
msgbox:toFront()
–[[
msgbox.text = “crap”
msgbox:toFront()
]]–
–LOAD MAP ------------------------------------------------------------
mte.toggleWorldWrapX(false)
mte.toggleWorldWrapY(false)
mte.loadTileSet(“dungeon3DMap”, “tilesets/dungeon3DMap.png”)
mte.loadTileSet(“innerFlat”, “tilesets/innerFlat.png”)
mte.loadTileSet(“castle3DMap”, “tilesets/castle3DMap.png”)
mte.loadTileSet(“townFlat”, “tilesets/townFlat.png”)
mte.loadTileSet(“Stone”, “tilesets/Stone.png”)
mte.loadTileSet(“brickwall”, “tilesets/brickwall.png”)
local startx = 49
local starty = 86
–mte.loadMap(“map/test”)
–mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
–mte.loadMap(“map/castle”)
–mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
mte.loadMap(“map/castle2”)
mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
mte.zoom(1.4, 0, “inOutQuad”)
–mte.fadeMap(0.5, 1)
–SETUP D-PAD ------------------------------------------------------------
local controlGroup = display.newGroup()
local DpadBack = display.newImageRect(controlGroup, “images/dpad.png”, 128, 128)
DpadBack.isVisible = true
DpadBack.x = 80
DpadBack.y = display.viewableContentHeight - 65
local DpadUp = display.newRect(controlGroup, DpadBack.x - 27, DpadBack.y - 64, 41, 41)
local DpadDown = display.newRect(controlGroup, DpadBack.x - 27, DpadBack.y + 10, 41, 41)
local DpadLeft = display.newRect(controlGroup, DpadBack.x - 64, DpadBack.y - 27, 41, 41)
local DpadRight = display.newRect(controlGroup, DpadBack.x + 10, DpadBack.y - 27, 41, 41)
DpadBack:toFront()
DpadUp.alpha = 0
DpadUp.isHitTestable = true
DpadDown.alpha = 0
DpadDown.isHitTestable = true
DpadLeft.alpha = 0
DpadLeft.isHitTestable = true
DpadRight.alpha = 0
DpadRight.isHitTestable = true
–HIDE LEVELS ------------------------------------------------------------
local layers = mte.getLayers()
local layerObjects = mte.getLayerObj()
for i = 1, #layers, 1 do
if not layers[i].properties.objectLayer then
end
if layers[i].properties.level > 2 then
mte.fadeLayer(i, 0, 0)
end
end
local tempS = layers[#layers].properties.scale
local tempM = (1 / 0.85) / tempS
–CREATE PLAYER SPRITE ------------------------------------------------------------
local spriteSheet = graphics.newImageSheet(“spriteSheet.png”, {width = 32, height = 32, numFrames = 96})
local spriteSheetmaiden = graphics.newImageSheet(“images/player-maiden.png”, {width = 32, height = 32, numFrames = 48})
local sequenceData = {
{name = “stand-down”, sheet = spriteSheetmaiden, frames = {9}, time = 400, loopCount = 0},
{name = “stand-up”, sheet = spriteSheetmaiden, frames = {12}, time = 400, loopCount = 0},
{name = “stand-right”, sheet = spriteSheetmaiden, frames = {10}, time = 400, loopCount = 0},
{name = “stand-left”, sheet = spriteSheetmaiden, frames = {11}, time = 400, loopCount = 0},
{name = “down”, sheet = spriteSheetmaiden, frames = {17,18,19,20,21,22}, time = 400, loopCount = 0},
{name = “up”, sheet = spriteSheetmaiden, frames = {41,42,43,44,45,46}, time = 400, loopCount = 0},
{name = “left”, sheet = spriteSheetmaiden, frames = {33,34,35,36,37,38}, time = 400, loopCount = 0},
{name = “right”, sheet = spriteSheetmaiden, frames = {25,26,27,28,29,30}, time = 400, loopCount = 0}
}
local player = display.newSprite(spriteSheetmaiden, sequenceData)
local setup = {
kind = “sprite”,
layer = mte.getSpriteLayer(1),
locX = startx,
locY = starty,
levelWidth = 32,
levelHeight = 32,
offsetY = 0
}
mte.addSprite(player, setup)
mte.setCameraFocus(player)
–CREATE 2D POSITION AND MOVEMENT VARIABLES --------------------------------------------
local mod = 30 / display.fps
local accx = 0
local accy = 0
local velX = 0
local velY = 0
local maxVelX = 5 * mod
local maxVelY = 5 * mod
local gravity = 0
local friction = 1.5 * mod * mod
–CREATE COLLISION DETECTION COORDINATES -----------------------------------------------
–[[
In this sample the player is a rectangle 32 pixels across and 32 pixels wide with an
offset of -16 in the Y direction.
The origin of a sprite is it’s center, but in this case, due to the -16 pixel offset, the
origin of the sprite as reckoned by MTE is 16 pixels from the bottom of the sprite, or
the center of the lower tile in the stack.
To detect platforms and obstacles around the player we must define points around the
player to be checked by our code. There are many ways to do this, but in this example the
points are defined in relation to the player sprite. The top1 and top2 points are along
the top of the player sprite. The sprite is 32 pixels high and the origin is 16 pixels from
it’s bottom, so the top is -16 pixels from the origin. The rest of the points are defined
in the same manner.
]]–
local offsets = {top1 = {-12, -16},
top2 = {12, -16},
bottom1 = {0, 16},
bottom2 = {12, 16},
left1 = {-12, 0},
left2 = {-12, 0},
right1 = {12, 0},
right2 = {12, 0}
}
–[[
These are variables for storing the true coordinates of the collision detection
points in relation to the level rather than the player sprite. These values are
calculated by the detectObstacle function below, which is called in an enterFrame.
]]–
local sensors = {top1 = {},
top2 = {},
bottom1 = {},
bottom2 = {},
left1 = {},
left2 = {},
right1 = {},
right2 = {}
}
local detect = {}
–OBSTACLE DETECTION FUNCTION-----------------------------------------------------------
local detectObstacle = function()
--CALCULATE SENSOR POSITIONS
local playerPosX = player.getLevelPosX() + velX
local playerPosY = player.getLevelPosY() + velY
sensors.top1[1], sensors.top1[2] = playerPosX + offsets.top1[1], playerPosY + offsets.top1[2]
sensors.top2[1], sensors.top2[2] = playerPosX + offsets.top2[1], playerPosY + offsets.top2[2]
sensors.bottom1[1], sensors.bottom1[2] = playerPosX + offsets.bottom1[1], playerPosY + offsets.bottom1[2]
sensors.bottom2[1], sensors.bottom2[2] = playerPosX + offsets.bottom2[1], playerPosY + offsets.bottom2[2]
sensors.left1[1], sensors.left1[2] = playerPosX + offsets.left1[1], playerPosY + offsets.left1[2]
sensors.left2[1], sensors.left2[2] = playerPosX + offsets.left2[1], playerPosY + offsets.left2[2]
sensors.right1[1], sensors.right1[2] = playerPosX + offsets.right1[1], playerPosY + offsets.right1[2]
sensors.right2[1], sensors.right2[2] = playerPosX + offsets.right2[1], playerPosY + offsets.right2[2]
--CHECK FOR TILE PROPERTIES
detect.top1 = mte.getTileProperties({levelPosX = sensors.top1[1], levelPosY = sensors.top1[2], layer = 4})
detect.top2 = mte.getTileProperties({levelPosX = sensors.top2[1], levelPosY = sensors.top2[2], layer = 4})
detect.bottom1 = mte.getTileProperties({levelPosX = sensors.bottom1[1], levelPosY = sensors.bottom1[2], layer = 4})
detect.bottom2 = mte.getTileProperties({levelPosX = sensors.bottom2[1], levelPosY = sensors.bottom2[2], layer = 4})
detect.left1 = mte.getTileProperties({levelPosX = sensors.left1[1], levelPosY = sensors.left1[2], layer = 4})
detect.left2 = mte.getTileProperties({levelPosX = sensors.left2[1], levelPosY = sensors.left2[2], layer = 4})
detect.right1 = mte.getTileProperties({levelPosX = sensors.right1[1], levelPosY = sensors.right1[2], layer = 4})
detect.right2 = mte.getTileProperties({levelPosX = sensors.right2[1], levelPosY = sensors.right2[2], layer = 4})
end
–MOVEMENT TOUCH EVENT ------------------------------------------------------------------
–[[
Our Dpad event does not directly move the player sprite or even set it’s velocity.
Instead we set the acceleration along the X axis. Our enterframe loop will then
increment the velocity along the X axis by this acceleration every frame.
]]–
local moveup = function(event)
player:setSequence( “up” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accy = -0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accy = 0
player:pause()
end
return true
end
local movedown = function(event)
player:setSequence( “down” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accy = 0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accy = 0
player:pause()
end
return true
end
local moveright = function(event)
player:setSequence( “right” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accx = 0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accx = 0
player:pause()
player:setSequence( “stand-right” )
end
return true
end
local moveleft = function(event)
player:setSequence( “left” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accx = -0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accx = 0
player:pause()
end
return true
end
–[[ before split into 4
local move = function(event)
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if(
if event.phase == “began” or event.phase == “moved” then
if event.x < event.target.x then
acc = -0.5 * mod * mod
end
if event.x > event.target.x then
acc = 0.5 * mod * mod
end
end
if event.phase == “began” or event.phase == “moved” then
if event.y < event.target.y then
acc = -0.5 * mod * mod
end
if event.y > event.target.y then
acc = 0.5 * mod * mod
end
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
acc = 0
end
return true
end
]]–
DpadUp:addEventListener(“touch”, moveup)
DpadDown:addEventListener(“touch”, movedown)
DpadLeft:addEventListener(“touch”, moveleft)
DpadRight:addEventListener(“touch”, moveright)
–[[ OLD WAY
local function gameLoop( event )
if not player.isMoving then
--CHECK FOR OBJECTS
local objects = mte.getObject({level = player.level, locX = player.locX, locY = player.locY})
if objects then
for key,value in pairs(objects[1].properties) do
if key == “change level” then
mte.changeSpriteLayer(player, mte.getSpriteLayer(tonumber(value)))
--UNCOMMENT TO ZOOM MAP ON LEVEL CHANGE, UNCOMMENT LINE 42 TO SET PROPER ZOOM AT START
--mte.zoom(1 / (tempM * layers[player.layer].properties.scale), moveTime, “inOutQuad”)
end
if key == “show level” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if value == “above” then
for i = 1, #layers, 1 do
if layers[i].properties.level > player.level then
mte.fadeLayer(i, 1, moveTime)
end
end
elseif value == “below” then
for i = 1, #layers, 1 do
if layers[i].properties.level < player.level then
mte.fadeLayer(i, 1, moveTime)
end
end
else
for i = 1, #layers, 1 do
if layers[i].properties.level == tonumber(value) then
mte.fadeLayer(i, 1, moveTime)
end
end
end
end
if key == “hide level” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if value == “above” then
for i = 1, #layers, 1 do
if layers[i].properties.level > player.level then
mte.fadeLayer(i, 0, moveTime)
end
end
elseif value == “below” then
for i = 1, #layers, 1 do
if layers[i].properties.level < player.level then
mte.fadeLayer(i, 0, moveTime)
end
end
else
for i = 1, #layers, 1 do
if layers[i].properties.level == tonumber(value) then
mte.fadeLayer(i, 0, moveTime)
end
end
end
end
local locX, locY, time = player.locX, player.locY, 250
if key == “move to locX” then
if value == “random” then
locX = player.locX + math.random(1, 3) - 2
else
locX = tonumber(value)
end
end
if key == “move to locY” then
if value == “random” then
locY = player.locY + math.random(1, 3) - 2
else
locY = tonumber(value)
end
end
if math.abs(locX - player.locX) > 3 or math.abs(locY - player.locY) > 3 then
time = 500
end
if locX ~= player.locX or locY ~= player.locY then
mte.moveSpriteTo({sprite = player, locX = locX, locY = locY, time = time, easing = “inOutQuad”})
end
end
end
end
mte.debug()
mte.update()
end
DpadUp:addEventListener(“touch”, move)
DpadDown:addEventListener(“touch”, move)
DpadLeft:addEventListener(“touch”, move)
DpadRight:addEventListener(“touch”, move)
Runtime:addEventListener(“enterFrame”, gameLoop)
]]–
–[[ OLD: LISTEN FOR TOUCH TO MOVE PLAYER
local screenTouch = function(event)
if event.phase ~= “ended” then
local layer = 5
msgbox.text = “in LISTEN FOR TOUCH TO MOVE PLAYER”
local screenPosToLevelPos = mte.convert(“screenPosToLevelPos”, event.x, event.y, layer)
local screenPosToLoc = mte.convert(“screenPosToLoc”, event.x, event.y, layer)
local screenPosToGrid = mte.convert(“screenPosToGrid”, event.x, event.y, layer)
local gridToScreenPos = mte.convert(“gridToScreenPos”, screenPosToGrid.x, screenPosToGrid.y, layer)
local gridToLoc = mte.convert(“gridToLoc”, screenPosToGrid.x, screenPosToGrid.y, layer)
local gridToLevelPos = mte.convert(“gridToLevelPos”, screenPosToGrid.x, screenPosToGrid.y, layer)
local locToScreenPos = mte.convert(“locToScreenPos”, screenPosToLoc.x, screenPosToLoc.y, layer)
local locToLevelPos = mte.convert(“locToLevelPos”, screenPosToLoc.x, screenPosToLoc.y, layer)
local locToGrid = mte.convert(“locToGrid”, screenPosToLoc.x, screenPosToLoc.y, layer)
local levelPosToScreenPos = mte.convert(“levelPosToScreenPos”, screenPosToLevelPos.x, screenPosToLevelPos.y, layer)
local levelPosToLoc = mte.convert(“levelPosToLoc”, locToLevelPos.x, locToLevelPos.y, layer)
local levelPosToGrid = mte.convert(“levelPosToGrid”, screenPosToLevelPos.x, screenPosToLevelPos.y, layer)
--mte.moveSpriteTo({player, locX = gridToLoc.x, locY = gridToLoc.y, time = 30, easing = “inOutExpo” })
print("Screen Position (click event): “…event.x…” "…event.y)
print("Screen Position (grid): “…gridToScreenPos.x…” "…gridToScreenPos.y)
print("Screen Position (location): “…locToScreenPos.x…” "…locToScreenPos.y)
print("Screen Position (level position): “…levelPosToScreenPos.x…” "…levelPosToScreenPos.y)
print(" ")
print("Level Position (screen position): “…screenPosToLevelPos.x…” "…screenPosToLevelPos.y)
print("Level Position (grid): “…gridToLevelPos.x…” "…gridToLevelPos.y)
print("Level Position (location): “…locToLevelPos.x…” "…locToLevelPos.y)
print(" ")
print("Location (screen position): “…screenPosToLoc.x…” "…screenPosToLoc.y)
print("Location (grid): “…gridToLoc.x…” "…gridToLoc.y)
print("Location (level position): “…levelPosToLoc.x…” "…levelPosToLoc.y)
print(" ")
print("Grid (screenPosition): “…screenPosToGrid.x…” "…screenPosToGrid.y)
print("Grid (location): “…locToGrid.x…” "…locToGrid.y)
print("Grid (level position): “…levelPosToGrid.x…” "…levelPosToGrid.y)
print(" ")
print("=======================================================")
end
end
Runtime:addEventListener(“touch”, screenTouch)
]]–
–ENTERFRAME----------------------------------------------------------------------------
local tempVelY
local tempVelX
local gameLoop = function(event)
--UPDATE VELOCITY, CONSTRAIN TO MAX VELOCITY
--[[
This is where the accelerations we created are applied to the player’s velocity.
It is important to constrain the velocity to a value lower than the dimensions of our
tiles in level coordinates, otherwise the sprite could pass through a tile in a single
frame without detecting it.
]]--
velX = velX + accx
if velX > maxVelX then
velX = maxVelX
elseif velX < maxVelX * -1 then
velX = maxVelX * -1
end
velY = velY + accy
if velY > maxVelY then
velY = maxVelY
elseif velY < maxVelY * -1 then
velY = maxVelY * -1
end
--APPLY FRICTION
--[[
Friction is similar to gravity, however it acts along the X axis and always
acts opposite to the player’s direction of motion. We only apply friction when
acceleration = 0 in this sample project because the acceleration applied by our
Dpad movement function is always stronger than the friction opposing it.
]]–
if accx == 0 then
if velX >= friction then
velX = velX - friction
elseif velX > 0 and velX < friction then
velX = 0
end
if velX <= friction * -1 then
velX = velX - friction * -1
elseif velX < 0 and velX > friction * -1 then
velX = 0
end
end
if accy == 0 then
if velY >= friction then
velY = velY - friction
elseif velY > 0 and velY < friction then
velY = 0
end
if velY <= friction * -1 then
velY = velY - friction * -1
elseif velY < 0 and velY > friction * -1 then
velY = 0
end
end
--COLLISION DETECTION
--[[
Calling detectObstacle() fills out our sensor array with the true level coordinates
of the collision detection points we defined. It then checks to see if tiles exist
at any of those points and fills the detect array with their properties.
]]--
detectObstacle()
--[[
We create temporary velocity variables so that we can perform operations on the
velocity for each of the collision detection routines without losing the original
velocity value.
]]–
tempVelY = velY
tempVelX = velX
--CHECK FOR FLOOR COLLISION
--[[
This code section checks to see if the tiles detected by detectObstacle() have
any properties and if one of those properties is named “solid.” The value stored in
the solid property is irrelevant in this sample project: the existence of the property
determines whether a tile is considered solid.
loc1X and loc1Y are the locations of the tile, computed with an MTE convert
function. These values are then fed into a second convert call to find the level
coordinates of the tile: pos1X, pos1Y. We now know the coordinates of the player
sprite’s sensors and the coordinates of the tile. With this information we compute
how much velocity would be necessary to move the player sprite to the surface of the
tile without ending up inside of it.
For example, say the player sprite is ten pixels above a solid tile and it is moving
down with a velocity of 20. The detectObstacle() function would detect that the sensor
point is inside a solid tile (sensors are computed as the player position + the collision
point’s offset + the player’s velocity). We would then find the level coordinates of the tile.
With a simple calculation we see that in order for the player to land on top of the tile
rather than inside it, the sprite’s velocity must be 10, not 20. So we set the
velocity to ten. The result is that the player lands on the tile. To the naked eye this
sudden deceleration from 20 to 10 is unnoticeable.
The code sections “CHECK FOR CEILING COLLISION,” “CHECK FOR LEFT WALL COLLISION,”
and “CHECK FOR RIGHT WALL COLLISION,” work in much the same way.
]]–
if detect.bottom1 and detect.bottom1.solid
or detect.bottom2 and detect.bottom2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.bottom1[1]), mte.convert(“levelPosToLoc”, nil, sensors.bottom1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velY > 0 then
tempVelY = velY + (pos1Y - sensors.bottom1[2])
velY = 0
end
end
--CHECK FOR CEILING COLLISION
if detect.top1 and detect.top1.solid
or detect.top2 and detect.top2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.top1[1]), mte.convert(“levelPosToLoc”, nil, sensors.top1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velY < 0 then
tempVelY = velY + (pos1Y - sensors.top1[2] + mte.worldScaleY)
velY = 0
end
end
--CHECK FOR LEFT WALL COLLISION
if detect.left1 and detect.left1.solid
or detect.left2 and detect.left2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.left1[1]), mte.convert(“levelPosToLoc”, nil, sensors.left1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velX < 0 then
tempVelX = velX + (pos1X - sensors.left1[1] + mte.worldScaleX)
velX = 0
end
end
--CHECK FOR RIGHT WALL COLLISION
if detect.right1 and detect.right1.solid
or detect.right2 and detect.right2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.right1[1]), mte.convert(“levelPosToLoc”, nil, sensors.right1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velX > 0 then
tempVelX = velX + (pos1X - sensors.right1[1])
velX = 0
end
end
mte.moveSprite(player, tempVelX, tempVelY)
mte.update()
mte.debug()
end
–jumpBtn:addEventListener(“touch”, jump)
Runtime:addEventListener(“enterFrame”, gameLoop)
It would seem that your map is not loading correctly. What does the terminal output before you encounter this runtime error?
2013-08-01 22:23:24.000 Corona Simulator[4322:f03] Version: 2.0.0
2013-08-01 22:23:24.001 Corona Simulator[4322:f03] Build: 2013.1076
2013-08-01 22:23:24.018 Corona Simulator[4322:f03] The file sandbox for this project is located at the following folder:
(/Users/steve/Library/Application Support/Corona Simulator/Raiders - movement-4C2F1EC2377AAC0088E1836067CD45C5)
2013-08-01 22:23:24.022 Corona Simulator[4322:f03] WARNING: Simulator does not support multitouch events
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] WARNING: Invalid fontSize(0) supplied. Using system standard size(13).
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] map/castle2.json loaded
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] Runtime error
…/!!IPAD GAMES/raiders/Raiders - movement/MTE/mte.lua:3119: attempt to index upvalue ‘map’ (a nil value)
stack traceback:
[C]: ?
…/!!IPAD GAMES/raiders/Raiders - movement/MTE/mte.lua:3119: in function ‘loadMap’
…ome/!!IPAD GAMES/raiders/Raiders - movement/main.lua:37: in main chunk
Well, that wasn’t nearly as telling as I would have hoped. If you email your project to me I’ll take a look at it and get to the bottom of the problem. I’ve PM’ed you with my email address in case you don’t have it.
I run into this sometimes and just revert to a previous change and step through the code but never find anything conclusive. Usually I don’t run into it again. Was curious if this was ever resolved?
In this particular case the map file had the .json extension but contained XML formatted data, which MTE does not currently read.
It all makes sense. I’ve been guilty of this from time to time :lol:.
This is usually a scope issue
If you could post your main.lua code that would be helpful. The terminal error itself doesn’t tell me much.
display.setStatusBar( display.HiddenStatusBar )
system.activate( “multitouch” )
display.setDefault( “magTextureFilter”, “nearest” )
display.setDefault( “minTextureFilter”, “nearest” )
–Load up MTE
local mte = require “MTE.mte”
local json = require “json”
–Message Box–
local msgbox
msgbox = display.newText(“null”, 60, 130, native.systemFont, size)
msgbox:setTextColor(255, 0, 0)
msgbox:toFront()
–[[
msgbox.text = “crap”
msgbox:toFront()
]]–
–LOAD MAP ------------------------------------------------------------
mte.toggleWorldWrapX(false)
mte.toggleWorldWrapY(false)
mte.loadTileSet(“dungeon3DMap”, “tilesets/dungeon3DMap.png”)
mte.loadTileSet(“innerFlat”, “tilesets/innerFlat.png”)
mte.loadTileSet(“castle3DMap”, “tilesets/castle3DMap.png”)
mte.loadTileSet(“townFlat”, “tilesets/townFlat.png”)
mte.loadTileSet(“Stone”, “tilesets/Stone.png”)
mte.loadTileSet(“brickwall”, “tilesets/brickwall.png”)
local startx = 49
local starty = 86
–mte.loadMap(“map/test”)
–mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
–mte.loadMap(“map/castle”)
–mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
mte.loadMap(“map/castle2”)
mte.goto({ locX = startx, locY = starty, blockScaleX = 32, blockScaleY = 32})
mte.zoom(1.4, 0, “inOutQuad”)
–mte.fadeMap(0.5, 1)
–SETUP D-PAD ------------------------------------------------------------
local controlGroup = display.newGroup()
local DpadBack = display.newImageRect(controlGroup, “images/dpad.png”, 128, 128)
DpadBack.isVisible = true
DpadBack.x = 80
DpadBack.y = display.viewableContentHeight - 65
local DpadUp = display.newRect(controlGroup, DpadBack.x - 27, DpadBack.y - 64, 41, 41)
local DpadDown = display.newRect(controlGroup, DpadBack.x - 27, DpadBack.y + 10, 41, 41)
local DpadLeft = display.newRect(controlGroup, DpadBack.x - 64, DpadBack.y - 27, 41, 41)
local DpadRight = display.newRect(controlGroup, DpadBack.x + 10, DpadBack.y - 27, 41, 41)
DpadBack:toFront()
DpadUp.alpha = 0
DpadUp.isHitTestable = true
DpadDown.alpha = 0
DpadDown.isHitTestable = true
DpadLeft.alpha = 0
DpadLeft.isHitTestable = true
DpadRight.alpha = 0
DpadRight.isHitTestable = true
–HIDE LEVELS ------------------------------------------------------------
local layers = mte.getLayers()
local layerObjects = mte.getLayerObj()
for i = 1, #layers, 1 do
if not layers[i].properties.objectLayer then
end
if layers[i].properties.level > 2 then
mte.fadeLayer(i, 0, 0)
end
end
local tempS = layers[#layers].properties.scale
local tempM = (1 / 0.85) / tempS
–CREATE PLAYER SPRITE ------------------------------------------------------------
local spriteSheet = graphics.newImageSheet(“spriteSheet.png”, {width = 32, height = 32, numFrames = 96})
local spriteSheetmaiden = graphics.newImageSheet(“images/player-maiden.png”, {width = 32, height = 32, numFrames = 48})
local sequenceData = {
{name = “stand-down”, sheet = spriteSheetmaiden, frames = {9}, time = 400, loopCount = 0},
{name = “stand-up”, sheet = spriteSheetmaiden, frames = {12}, time = 400, loopCount = 0},
{name = “stand-right”, sheet = spriteSheetmaiden, frames = {10}, time = 400, loopCount = 0},
{name = “stand-left”, sheet = spriteSheetmaiden, frames = {11}, time = 400, loopCount = 0},
{name = “down”, sheet = spriteSheetmaiden, frames = {17,18,19,20,21,22}, time = 400, loopCount = 0},
{name = “up”, sheet = spriteSheetmaiden, frames = {41,42,43,44,45,46}, time = 400, loopCount = 0},
{name = “left”, sheet = spriteSheetmaiden, frames = {33,34,35,36,37,38}, time = 400, loopCount = 0},
{name = “right”, sheet = spriteSheetmaiden, frames = {25,26,27,28,29,30}, time = 400, loopCount = 0}
}
local player = display.newSprite(spriteSheetmaiden, sequenceData)
local setup = {
kind = “sprite”,
layer = mte.getSpriteLayer(1),
locX = startx,
locY = starty,
levelWidth = 32,
levelHeight = 32,
offsetY = 0
}
mte.addSprite(player, setup)
mte.setCameraFocus(player)
–CREATE 2D POSITION AND MOVEMENT VARIABLES --------------------------------------------
local mod = 30 / display.fps
local accx = 0
local accy = 0
local velX = 0
local velY = 0
local maxVelX = 5 * mod
local maxVelY = 5 * mod
local gravity = 0
local friction = 1.5 * mod * mod
–CREATE COLLISION DETECTION COORDINATES -----------------------------------------------
–[[
In this sample the player is a rectangle 32 pixels across and 32 pixels wide with an
offset of -16 in the Y direction.
The origin of a sprite is it’s center, but in this case, due to the -16 pixel offset, the
origin of the sprite as reckoned by MTE is 16 pixels from the bottom of the sprite, or
the center of the lower tile in the stack.
To detect platforms and obstacles around the player we must define points around the
player to be checked by our code. There are many ways to do this, but in this example the
points are defined in relation to the player sprite. The top1 and top2 points are along
the top of the player sprite. The sprite is 32 pixels high and the origin is 16 pixels from
it’s bottom, so the top is -16 pixels from the origin. The rest of the points are defined
in the same manner.
]]–
local offsets = {top1 = {-12, -16},
top2 = {12, -16},
bottom1 = {0, 16},
bottom2 = {12, 16},
left1 = {-12, 0},
left2 = {-12, 0},
right1 = {12, 0},
right2 = {12, 0}
}
–[[
These are variables for storing the true coordinates of the collision detection
points in relation to the level rather than the player sprite. These values are
calculated by the detectObstacle function below, which is called in an enterFrame.
]]–
local sensors = {top1 = {},
top2 = {},
bottom1 = {},
bottom2 = {},
left1 = {},
left2 = {},
right1 = {},
right2 = {}
}
local detect = {}
–OBSTACLE DETECTION FUNCTION-----------------------------------------------------------
local detectObstacle = function()
--CALCULATE SENSOR POSITIONS
local playerPosX = player.getLevelPosX() + velX
local playerPosY = player.getLevelPosY() + velY
sensors.top1[1], sensors.top1[2] = playerPosX + offsets.top1[1], playerPosY + offsets.top1[2]
sensors.top2[1], sensors.top2[2] = playerPosX + offsets.top2[1], playerPosY + offsets.top2[2]
sensors.bottom1[1], sensors.bottom1[2] = playerPosX + offsets.bottom1[1], playerPosY + offsets.bottom1[2]
sensors.bottom2[1], sensors.bottom2[2] = playerPosX + offsets.bottom2[1], playerPosY + offsets.bottom2[2]
sensors.left1[1], sensors.left1[2] = playerPosX + offsets.left1[1], playerPosY + offsets.left1[2]
sensors.left2[1], sensors.left2[2] = playerPosX + offsets.left2[1], playerPosY + offsets.left2[2]
sensors.right1[1], sensors.right1[2] = playerPosX + offsets.right1[1], playerPosY + offsets.right1[2]
sensors.right2[1], sensors.right2[2] = playerPosX + offsets.right2[1], playerPosY + offsets.right2[2]
--CHECK FOR TILE PROPERTIES
detect.top1 = mte.getTileProperties({levelPosX = sensors.top1[1], levelPosY = sensors.top1[2], layer = 4})
detect.top2 = mte.getTileProperties({levelPosX = sensors.top2[1], levelPosY = sensors.top2[2], layer = 4})
detect.bottom1 = mte.getTileProperties({levelPosX = sensors.bottom1[1], levelPosY = sensors.bottom1[2], layer = 4})
detect.bottom2 = mte.getTileProperties({levelPosX = sensors.bottom2[1], levelPosY = sensors.bottom2[2], layer = 4})
detect.left1 = mte.getTileProperties({levelPosX = sensors.left1[1], levelPosY = sensors.left1[2], layer = 4})
detect.left2 = mte.getTileProperties({levelPosX = sensors.left2[1], levelPosY = sensors.left2[2], layer = 4})
detect.right1 = mte.getTileProperties({levelPosX = sensors.right1[1], levelPosY = sensors.right1[2], layer = 4})
detect.right2 = mte.getTileProperties({levelPosX = sensors.right2[1], levelPosY = sensors.right2[2], layer = 4})
end
–MOVEMENT TOUCH EVENT ------------------------------------------------------------------
–[[
Our Dpad event does not directly move the player sprite or even set it’s velocity.
Instead we set the acceleration along the X axis. Our enterframe loop will then
increment the velocity along the X axis by this acceleration every frame.
]]–
local moveup = function(event)
player:setSequence( “up” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accy = -0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accy = 0
player:pause()
end
return true
end
local movedown = function(event)
player:setSequence( “down” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accy = 0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accy = 0
player:pause()
end
return true
end
local moveright = function(event)
player:setSequence( “right” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accx = 0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accx = 0
player:pause()
player:setSequence( “stand-right” )
end
return true
end
local moveleft = function(event)
player:setSequence( “left” )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if event.phase == “began” or event.phase == “moved” then
player:play()
accx = -0.5 * mod * mod
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
accx = 0
player:pause()
end
return true
end
–[[ before split into 4
local move = function(event)
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target, event.id)
event.target.isFocus = true
end
if(
if event.phase == “began” or event.phase == “moved” then
if event.x < event.target.x then
acc = -0.5 * mod * mod
end
if event.x > event.target.x then
acc = 0.5 * mod * mod
end
end
if event.phase == “began” or event.phase == “moved” then
if event.y < event.target.y then
acc = -0.5 * mod * mod
end
if event.y > event.target.y then
acc = 0.5 * mod * mod
end
end
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( event.target, nil )
event.target.isFocus = false
acc = 0
end
return true
end
]]–
DpadUp:addEventListener(“touch”, moveup)
DpadDown:addEventListener(“touch”, movedown)
DpadLeft:addEventListener(“touch”, moveleft)
DpadRight:addEventListener(“touch”, moveright)
–[[ OLD WAY
local function gameLoop( event )
if not player.isMoving then
--CHECK FOR OBJECTS
local objects = mte.getObject({level = player.level, locX = player.locX, locY = player.locY})
if objects then
for key,value in pairs(objects[1].properties) do
if key == “change level” then
mte.changeSpriteLayer(player, mte.getSpriteLayer(tonumber(value)))
--UNCOMMENT TO ZOOM MAP ON LEVEL CHANGE, UNCOMMENT LINE 42 TO SET PROPER ZOOM AT START
--mte.zoom(1 / (tempM * layers[player.layer].properties.scale), moveTime, “inOutQuad”)
end
if key == “show level” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if value == “above” then
for i = 1, #layers, 1 do
if layers[i].properties.level > player.level then
mte.fadeLayer(i, 1, moveTime)
end
end
elseif value == “below” then
for i = 1, #layers, 1 do
if layers[i].properties.level < player.level then
mte.fadeLayer(i, 1, moveTime)
end
end
else
for i = 1, #layers, 1 do
if layers[i].properties.level == tonumber(value) then
mte.fadeLayer(i, 1, moveTime)
end
end
end
end
if key == “hide level” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if value == “above” then
for i = 1, #layers, 1 do
if layers[i].properties.level > player.level then
mte.fadeLayer(i, 0, moveTime)
end
end
elseif value == “below” then
for i = 1, #layers, 1 do
if layers[i].properties.level < player.level then
mte.fadeLayer(i, 0, moveTime)
end
end
else
for i = 1, #layers, 1 do
if layers[i].properties.level == tonumber(value) then
mte.fadeLayer(i, 0, moveTime)
end
end
end
end
local locX, locY, time = player.locX, player.locY, 250
if key == “move to locX” then
if value == “random” then
locX = player.locX + math.random(1, 3) - 2
else
locX = tonumber(value)
end
end
if key == “move to locY” then
if value == “random” then
locY = player.locY + math.random(1, 3) - 2
else
locY = tonumber(value)
end
end
if math.abs(locX - player.locX) > 3 or math.abs(locY - player.locY) > 3 then
time = 500
end
if locX ~= player.locX or locY ~= player.locY then
mte.moveSpriteTo({sprite = player, locX = locX, locY = locY, time = time, easing = “inOutQuad”})
end
end
end
end
mte.debug()
mte.update()
end
DpadUp:addEventListener(“touch”, move)
DpadDown:addEventListener(“touch”, move)
DpadLeft:addEventListener(“touch”, move)
DpadRight:addEventListener(“touch”, move)
Runtime:addEventListener(“enterFrame”, gameLoop)
]]–
–[[ OLD: LISTEN FOR TOUCH TO MOVE PLAYER
local screenTouch = function(event)
if event.phase ~= “ended” then
local layer = 5
msgbox.text = “in LISTEN FOR TOUCH TO MOVE PLAYER”
local screenPosToLevelPos = mte.convert(“screenPosToLevelPos”, event.x, event.y, layer)
local screenPosToLoc = mte.convert(“screenPosToLoc”, event.x, event.y, layer)
local screenPosToGrid = mte.convert(“screenPosToGrid”, event.x, event.y, layer)
local gridToScreenPos = mte.convert(“gridToScreenPos”, screenPosToGrid.x, screenPosToGrid.y, layer)
local gridToLoc = mte.convert(“gridToLoc”, screenPosToGrid.x, screenPosToGrid.y, layer)
local gridToLevelPos = mte.convert(“gridToLevelPos”, screenPosToGrid.x, screenPosToGrid.y, layer)
local locToScreenPos = mte.convert(“locToScreenPos”, screenPosToLoc.x, screenPosToLoc.y, layer)
local locToLevelPos = mte.convert(“locToLevelPos”, screenPosToLoc.x, screenPosToLoc.y, layer)
local locToGrid = mte.convert(“locToGrid”, screenPosToLoc.x, screenPosToLoc.y, layer)
local levelPosToScreenPos = mte.convert(“levelPosToScreenPos”, screenPosToLevelPos.x, screenPosToLevelPos.y, layer)
local levelPosToLoc = mte.convert(“levelPosToLoc”, locToLevelPos.x, locToLevelPos.y, layer)
local levelPosToGrid = mte.convert(“levelPosToGrid”, screenPosToLevelPos.x, screenPosToLevelPos.y, layer)
--mte.moveSpriteTo({player, locX = gridToLoc.x, locY = gridToLoc.y, time = 30, easing = “inOutExpo” })
print("Screen Position (click event): “…event.x…” "…event.y)
print("Screen Position (grid): “…gridToScreenPos.x…” "…gridToScreenPos.y)
print("Screen Position (location): “…locToScreenPos.x…” "…locToScreenPos.y)
print("Screen Position (level position): “…levelPosToScreenPos.x…” "…levelPosToScreenPos.y)
print(" ")
print("Level Position (screen position): “…screenPosToLevelPos.x…” "…screenPosToLevelPos.y)
print("Level Position (grid): “…gridToLevelPos.x…” "…gridToLevelPos.y)
print("Level Position (location): “…locToLevelPos.x…” "…locToLevelPos.y)
print(" ")
print("Location (screen position): “…screenPosToLoc.x…” "…screenPosToLoc.y)
print("Location (grid): “…gridToLoc.x…” "…gridToLoc.y)
print("Location (level position): “…levelPosToLoc.x…” "…levelPosToLoc.y)
print(" ")
print("Grid (screenPosition): “…screenPosToGrid.x…” "…screenPosToGrid.y)
print("Grid (location): “…locToGrid.x…” "…locToGrid.y)
print("Grid (level position): “…levelPosToGrid.x…” "…levelPosToGrid.y)
print(" ")
print("=======================================================")
end
end
Runtime:addEventListener(“touch”, screenTouch)
]]–
–ENTERFRAME----------------------------------------------------------------------------
local tempVelY
local tempVelX
local gameLoop = function(event)
--UPDATE VELOCITY, CONSTRAIN TO MAX VELOCITY
--[[
This is where the accelerations we created are applied to the player’s velocity.
It is important to constrain the velocity to a value lower than the dimensions of our
tiles in level coordinates, otherwise the sprite could pass through a tile in a single
frame without detecting it.
]]--
velX = velX + accx
if velX > maxVelX then
velX = maxVelX
elseif velX < maxVelX * -1 then
velX = maxVelX * -1
end
velY = velY + accy
if velY > maxVelY then
velY = maxVelY
elseif velY < maxVelY * -1 then
velY = maxVelY * -1
end
--APPLY FRICTION
--[[
Friction is similar to gravity, however it acts along the X axis and always
acts opposite to the player’s direction of motion. We only apply friction when
acceleration = 0 in this sample project because the acceleration applied by our
Dpad movement function is always stronger than the friction opposing it.
]]–
if accx == 0 then
if velX >= friction then
velX = velX - friction
elseif velX > 0 and velX < friction then
velX = 0
end
if velX <= friction * -1 then
velX = velX - friction * -1
elseif velX < 0 and velX > friction * -1 then
velX = 0
end
end
if accy == 0 then
if velY >= friction then
velY = velY - friction
elseif velY > 0 and velY < friction then
velY = 0
end
if velY <= friction * -1 then
velY = velY - friction * -1
elseif velY < 0 and velY > friction * -1 then
velY = 0
end
end
--COLLISION DETECTION
--[[
Calling detectObstacle() fills out our sensor array with the true level coordinates
of the collision detection points we defined. It then checks to see if tiles exist
at any of those points and fills the detect array with their properties.
]]--
detectObstacle()
--[[
We create temporary velocity variables so that we can perform operations on the
velocity for each of the collision detection routines without losing the original
velocity value.
]]–
tempVelY = velY
tempVelX = velX
--CHECK FOR FLOOR COLLISION
--[[
This code section checks to see if the tiles detected by detectObstacle() have
any properties and if one of those properties is named “solid.” The value stored in
the solid property is irrelevant in this sample project: the existence of the property
determines whether a tile is considered solid.
loc1X and loc1Y are the locations of the tile, computed with an MTE convert
function. These values are then fed into a second convert call to find the level
coordinates of the tile: pos1X, pos1Y. We now know the coordinates of the player
sprite’s sensors and the coordinates of the tile. With this information we compute
how much velocity would be necessary to move the player sprite to the surface of the
tile without ending up inside of it.
For example, say the player sprite is ten pixels above a solid tile and it is moving
down with a velocity of 20. The detectObstacle() function would detect that the sensor
point is inside a solid tile (sensors are computed as the player position + the collision
point’s offset + the player’s velocity). We would then find the level coordinates of the tile.
With a simple calculation we see that in order for the player to land on top of the tile
rather than inside it, the sprite’s velocity must be 10, not 20. So we set the
velocity to ten. The result is that the player lands on the tile. To the naked eye this
sudden deceleration from 20 to 10 is unnoticeable.
The code sections “CHECK FOR CEILING COLLISION,” “CHECK FOR LEFT WALL COLLISION,”
and “CHECK FOR RIGHT WALL COLLISION,” work in much the same way.
]]–
if detect.bottom1 and detect.bottom1.solid
or detect.bottom2 and detect.bottom2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.bottom1[1]), mte.convert(“levelPosToLoc”, nil, sensors.bottom1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velY > 0 then
tempVelY = velY + (pos1Y - sensors.bottom1[2])
velY = 0
end
end
--CHECK FOR CEILING COLLISION
if detect.top1 and detect.top1.solid
or detect.top2 and detect.top2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.top1[1]), mte.convert(“levelPosToLoc”, nil, sensors.top1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velY < 0 then
tempVelY = velY + (pos1Y - sensors.top1[2] + mte.worldScaleY)
velY = 0
end
end
--CHECK FOR LEFT WALL COLLISION
if detect.left1 and detect.left1.solid
or detect.left2 and detect.left2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.left1[1]), mte.convert(“levelPosToLoc”, nil, sensors.left1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velX < 0 then
tempVelX = velX + (pos1X - sensors.left1[1] + mte.worldScaleX)
velX = 0
end
end
--CHECK FOR RIGHT WALL COLLISION
if detect.right1 and detect.right1.solid
or detect.right2 and detect.right2.solid then
local loc1X, loc1Y = mte.convert(“levelPosToLoc”, sensors.right1[1]), mte.convert(“levelPosToLoc”, nil, sensors.right1[2])
local pos1X, pos1Y = mte.convert(“locToLevelPos”, loc1X) - mte.worldScaleX * 0.5, mte.convert(“locToLevelPos”, nil, loc1Y) - mte.worldScaleY * 0.5
if velX > 0 then
tempVelX = velX + (pos1X - sensors.right1[1])
velX = 0
end
end
mte.moveSprite(player, tempVelX, tempVelY)
mte.update()
mte.debug()
end
–jumpBtn:addEventListener(“touch”, jump)
Runtime:addEventListener(“enterFrame”, gameLoop)
It would seem that your map is not loading correctly. What does the terminal output before you encounter this runtime error?
2013-08-01 22:23:24.000 Corona Simulator[4322:f03] Version: 2.0.0
2013-08-01 22:23:24.001 Corona Simulator[4322:f03] Build: 2013.1076
2013-08-01 22:23:24.018 Corona Simulator[4322:f03] The file sandbox for this project is located at the following folder:
(/Users/steve/Library/Application Support/Corona Simulator/Raiders - movement-4C2F1EC2377AAC0088E1836067CD45C5)
2013-08-01 22:23:24.022 Corona Simulator[4322:f03] WARNING: Simulator does not support multitouch events
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] WARNING: Invalid fontSize(0) supplied. Using system standard size(13).
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] map/castle2.json loaded
2013-08-01 22:23:24.030 Corona Simulator[4322:f03] Runtime error
…/!!IPAD GAMES/raiders/Raiders - movement/MTE/mte.lua:3119: attempt to index upvalue ‘map’ (a nil value)
stack traceback:
[C]: ?
…/!!IPAD GAMES/raiders/Raiders - movement/MTE/mte.lua:3119: in function ‘loadMap’
…ome/!!IPAD GAMES/raiders/Raiders - movement/main.lua:37: in main chunk
Well, that wasn’t nearly as telling as I would have hoped. If you email your project to me I’ll take a look at it and get to the bottom of the problem. I’ve PM’ed you with my email address in case you don’t have it.
Thank you. That was it. I must remember to simply “export” as json. Thanks
I run into this sometimes and just revert to a previous change and step through the code but never find anything conclusive. Usually I don’t run into it again. Was curious if this was ever resolved?
In this particular case the map file had the .json extension but contained XML formatted data, which MTE does not currently read.
It all makes sense. I’ve been guilty of this from time to time :lol:.