Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

main.lua:39: attempt to call method 'setLinearvelocity' (a nil value)
Started by 15010006 Feb 19 2018 11:46 AM

3 replies to this topic
lua game nil value help newbie
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

15010006

[GLOBAL: userInfoPane.html]
15010006
  • Observer

  • 2 posts
  • Corona SDK

Im having trouble with my game that I am making which is like a ping pong game where when the ball touches the blocks but I keep having a problem where its saying setLinearvelocity is a nil value if anyone could help please do.

 

local w = display.contentWidth
local h = display.contentHeight
 
local fisica = require("physics")
fisica.start()
fisica.setGravity(0,0)
local bg = display.newRect(w/2,h/2,w,h)
 
 
local pg = display.newRoundedRect(w/2,h-h/20,w/4,h/30,30)
pg:setFillColor(0,0,0)
fisica.addBody(pg, "static")
local function movePg(event)
pg.x = event.x
end
Runtime:addEventListener("touch", movePg)
 
local larghezza = w/6 - w/20
local altezza = h/20 - h/30
 
for i=1,5,2 do
for j=1,11,2 do
local enemy = display.newRoundedRect(w/12*j,h/20*i,larghezza,altezza,30)
enemy:setFillColor(0,0,0)
fisica.addBody(enemy, "static")
 
local function collisione(self, event)
self:removeSelf()
end
enemy.collision = collisione
enemy:addEventListener("collision")
end
 
end
 
local ball = display.newCircle(w/2,h/2,w/40)
ball:setFillColor(0,0,0)
fisica.addBody(ball, "dynamic", {bounce=1})
ball:setLinearvelocity(w/2, w/2)
 
local wallSx = display.newRect(w/20,h/2,w/10,h)
local wallDx = display.newRect(w*w/20,h/2, w/10, h)
fisica.addBody(wallSx, "static")
fisica.addBody(wallDx, "static")


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,750 posts
  • Corona SDK

1. Please format code posts.  Also, help us out in the future by marking the line in question so we don't have to count or find it on our own.

formatyourcode.jpg

 

 

2. It means the object wasn't created or the body wasn't added (the latter this time).

 

 

Update: SEE DAVE's answer below for actual problem.

3. This is the problem:

fisica.addBody(ball, "dynamic", {bounce=1})


-- what is fisica?  I think you mean physics

Edited by roaminggamer, 20 February 2018 - 08:57 AM.


[TOPIC: post.html]
#3

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,138 posts
  • Enterprise

needs capital "V", Lua is case-sensitive



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,750 posts
  • Corona SDK

Dave is right.  Also I just noticed this:

local fisica = require("physics")

Thus explaining your non-standard (but still correct) code for the addBody() statements.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: lua, game, nil value, help, newbie