Is the current documentation up to date?

I am brand new. I was following a tutorial on basic object spawning, but I kept getting errors with regards to where I placed commas and what not. I understand solar2d has gone over a number of changes since it switched over from Corona. How do I know for certain that the tutorial I was following was up to date? Here’s a link to the tutorial.

Non-breaking changes has always been the focus. As such, there should be no breaking changes in the tutorials.

1 Like

I’m using code based on that tutorial in the game i’m working on. It works for me.

Post what you have.

I’ve just given that tutorial a quick scan, and can’t see anything that looks wrong. You specifically mentioned errors about commas, but every comma I can see in that sample looks correct.

Is it possible you were trying to extend what the tutorial code does, and made a few syntax errors when adding additional functionality?

tutorial this is for the beginner to learn how to do. However if you encounter an error, post this error code and we will help you.

Thanks everyone. I used the code in a separate file and it worked. I guess the issue is I’m trying to sandwich it into something I was already working on and it caused some issues. I am trying to make a tile-matching kind of game. I was going to try to get the spawn parameters to be coordinates in the grid but I wanted to just follow the tutorial’s parameters for now.

The error I’m getting right now is "main.lua81: Unexpected symbol near ‘local’. So it would be at “local function spawnItem( bounds )”

--Layout
local relayout = require("relayout")

local _W, _H, _CX, _CY = relayout._W, relayout._H, relayout._CX, relayout._CY

--Variables

local physics = require( "physics" )
physics.start()

--grid

local GRID_WIDTH = 7
local GRID_HEIGHT = 15
local CELL_WIDTH = 39
local CELL_HEIGHT = 39

local grid = {}
for i = 1, GRID_HEIGHT do
	grid[i] = {}
end

local board = display.newImageRect( "grid.png", 280, 600 )
board.x = _CX
board.y = _CY

local gbOffsetX = board.x - ( board.width * board.anchorX ) 
local gbOffsetY = board.y - ( board.height * board.anchorY )


--squares

local water = display.newRect (_CX, _CY, 39, 39)
water:setFillColor (0.53, 0.81, 0.94 )
--water.velocity = 0
--water.gravity = 0.1
physics.addBody (water, "dynamic", { density=1, bounce=0.0 }) 

local dirt = display.newRect (_CX, _CY + 280 , 39, 39)
dirt:setFillColor (0.39, 0.26, 0.12)
physics.addBody (dirt, "dynamic", { density=1, bounce=0.0 }) 
--
--collision

local function checkCollision(obj1, obj2)
    local  left = (obj1.contentBounds.xMin) <= obj2.contentBounds.xMin and (obj1.contentBounds.xMax) >= obj2.contentBounds.xMin
    local right = (obj1.contentBounds.xMin) >= obj2.contentBounds.xMin and (obj1.contentBounds.xMin) <= obj2.contentBounds.xMax
    local  up   = (obj1.contentBounds.yMin) <= obj2.contentBounds.yMin and (obj1.contentBounds.yMax) >= obj2.contentBounds.yMin
    local down  = (obj1.contentBounds.yMin) >= obj2.contentBounds.yMin and (obj1.contentBounds.yMin) <= obj2.contentBounds.yMax
 
    return (left or right) and (up or down)
    
end 

--floor

local floor = display.newRect (_CX, _CY + 319, _W * 3, 39)
floor:setFillColor (1, 0, 0 )
physics.addBody ( floor, "static", {bounce=0.0, friction=0.3 } )


--spawning

local spawnTimer
local spawnedItem = {}
-- Seed the random number generator
math.randomseed( os.time() )


local spawnParams = {
    xMin = 20,
    xMax = 300,
    yMin = 20,
    yMax = 460,
    spawnTime = 200,
    spawnOnTimer = 12,
    spawnInitial = 4
},

-- Spawn an item
local function spawnItem( bounds )
 
    -- Create an item
    local item = display.newCircle( 0, 0, 20 )
 
    -- Position item randomly within set bounds
    item.x = math.random( bounds.xMin, bounds.xMax )
    item.y = math.random( bounds.yMin, bounds.yMax )
 
    -- Add item to "spawnedObjects" table for tracking purposes
    spawnedObjects[#spawnedObjects+1] = item
end

local function spawnController( action, params )
 
    -- Cancel timer on "start" or "stop", if it exists
    if ( spawnTimer and ( action == "start" or action == "stop" ) ) then
        timer.cancel( spawnTimer )
    end
 
    -- Start spawning
    if ( action == "start" ) then
 
        -- Gather/set spawning bounds
        local spawnBounds = {}
        spawnBounds.xMin = params.xMin or 0
        spawnBounds.xMax = params.xMax or display.contentWidth
        spawnBounds.yMin = params.yMin or 0
        spawnBounds.yMax = params.yMax or display.contentHeight
 
        -- Gather/set other spawning params
        local spawnTime = params.spawnTime or 1000
        local spawnOnTimer = params.spawnOnTimer or 50
        local spawnInitial = params.spawnInitial or 0
 
        -- If "spawnInitial" is greater than 0, spawn that many item(s) instantly
        if ( spawnInitial > 0 ) then
            for n = 1,spawnInitial do
                spawnItem( spawnBounds )
            end
        end
 
        -- Start repeating timer to spawn items
        if ( spawnOnTimer > 0 ) then
            spawnTimer = timer.performWithDelay( spawnTime,
                function() spawnItem( spawnBounds ); end,
            spawnOnTimer )
        end
 
    -- Pause spawning
    elseif ( action == "pause" ) then
        timer.pause( spawnTimer )
 
    -- Resume spawning
    elseif ( action == "resume" ) then
        timer.resume( spawnTimer )
    end
end

spawnController( "start", spawnParams )

--
--update

-- local function update()

 --   water.velocity = water.velocity - water.gravity
   -- water.y = water.y - water.velocity
--end




--Runtime:addEventListener ("enterFrame", update)
 

Even though the error did mention that specific line, it was referring to the keyword’s position in this case, while the actual issue is on a different line — the unnecessary comma after the table spawnParams is closed already. Didn’t lie about it being “near local”, haha.

Thank you sir! I’m on the right track now.

1 Like