Code error

module(...,package.seeall) function newBullet()   local bullet=display.newImage("bulleth.png")   bullet.x=100   bullet.y=100   bullet.type="bullet"   physics.addBody(bullet,"kinematic",{density=0.2, friction=.2, bounce=.5, radius=20})   bullet.linearDampling=.3   bullet.angularDampling=.8   bullet.isBullet=true  --forces continous collison detection   bullet.isSensor=true    function bullet:touch(event)              if(event.phase=="began") then         display.getCurrentStage():setFocus( event.target )         self.isFocus=true         self.bodyType="kinematic"         --Stop current motion if any         self:setLinearVelocity(0,0)         self:angularVelocity=0 --line 28         myLine=nil         elseif(self.isFocus) then         if(event.phase=="moved") then         if (myLine) then         myLine.parent:remove(myLine) --erase previous line, if any         end         --Check this         myLine=display.newLine(self.x,self.y, event.x, event.y)         myLine:setColor(255,255,255,50)         myLine:width=8         elseif(event.phase=="ended" or event.phase=="cancelled") then                  display.getCurrentStage():setFocus(nil)                  self.isFocus=false                  if(myLine) then                   myLine.parent:remove(myLine)                  end                  --Launch bullet                  self.bodyType="dynamic"                  self:applyForce((self.x-event.x)\*force\_multiplier,(self.y-event.y)\*force\_multiplier, self.x, self.y)                           end        end    end   bullet:addEventListener("touch", bullet)     return bullet end

I am getting error in my code that says:

bullet.lua:28: function arguments expected near ‘=’

I am looking in my code and cannot see the error the system is talking about. Line 28 is marked in the code via comment.

Please help!

  1. Don’t use old-style modules

    module(…,package.seeall) function newBullet()

Do this:

-- Saved in mymodule.lua for this example local M = {} function M.newBullet() end ... return M

then to use it:

local someName = require "myModule" someName.newBullet()
  1. Thanks for posting using code formatting, but don’t forget to clean it up and make it legible before pasting:
  • Replace tabs with 3 spaces
  • Remove extra blank lines
  • Shift left as much as possible so it doesn’t wrap and become illegible.
  • Edit again if it isn’t legible till it is.  Don’t make us struggle to read the code.
  1. What is line 28?  It’s great to post the code, but be sure to point out what lines are the culprit or at least are getting the error.

Please clean that up and I’ll look again.

I marked line 28 in the code. Can you help now even though it was already marked.

Well, you didn’t clean it up, but …

self:angularVelocity=0 -- wrong

self.angularVelocity=0 -- correct

To add to what Ed said, using the colon (:slight_smile: operator implies you’re using a function. Any time you’re changing an attribute/variable value, you always use the period (.) separator (or I guess technically you could use self[“angularVelocity”] = 0 but who wants to do the extra typing), but the colon operator is used to pass a reference to the object into the function.

Rob

  1. Don’t use old-style modules

    module(…,package.seeall) function newBullet()

Do this:

-- Saved in mymodule.lua for this example local M = {} function M.newBullet() end ... return M

then to use it:

local someName = require "myModule" someName.newBullet()
  1. Thanks for posting using code formatting, but don’t forget to clean it up and make it legible before pasting:
  • Replace tabs with 3 spaces
  • Remove extra blank lines
  • Shift left as much as possible so it doesn’t wrap and become illegible.
  • Edit again if it isn’t legible till it is.  Don’t make us struggle to read the code.
  1. What is line 28?  It’s great to post the code, but be sure to point out what lines are the culprit or at least are getting the error.

Please clean that up and I’ll look again.

I marked line 28 in the code. Can you help now even though it was already marked.

Well, you didn’t clean it up, but …

self:angularVelocity=0 -- wrong

self.angularVelocity=0 -- correct

To add to what Ed said, using the colon (:slight_smile: operator implies you’re using a function. Any time you’re changing an attribute/variable value, you always use the period (.) separator (or I guess technically you could use self[“angularVelocity”] = 0 but who wants to do the extra typing), but the colon operator is used to pass a reference to the object into the function.

Rob