PDA

View Full Version : Lua problems



splodger15
October 30th, 2006, 20:06
I keep on getting this error code in my lua script
------------------------------------------------------------------
libpng error: not a PNG file

Here is my code
------------------------------------------------------------------

-- Created by splodger15


----------detect other cars collision--------------
function detectCollision(player, opponent)
if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
screen.waitVblankStart(60)
dofile("menu.lua")
end
end

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
background =Image.load ("images/road.PNG")
player1=Image.load("images/car1.PNG")
car2=Image.load("car2.PNG")
car3=Image.load("car3.PNG")
car4=Image.load("car4.PNG")

----------walls------------

wall1 = Image.createEmpty(480,2)
wall2 = Image.createEmpty(2,272)
wall3 = Image.createEmpty(2,272)
wall4 = Image.createEmpty(480,2)

wall1 = {x = 0, y = 0, height = wall1:height(), width = wall1:width() }
wall2 = {x = 450, y = 0, height = wall2:height(), width = wall2:width() }
wall3 = {x = 0, y = 0, height = wall3:height(), width = wall3:width() }
wall4 = {x = 0, y = 299, height = wall4:height(), width = wall4:width() }



player = {}
player.x = 250
player.y = 100
playerHeight = 63
playerWidth = 33

car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = car2

car3 = {}
car3.x = 228
car3.y = 20
car3Height = 63
car3Width = 33
car3.pic = car3

car4 = {}
car4.x = 28
car4.y = 20
car4Height = 63
car4Width = 33
car4.pic = car4

character = car1


------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)


if rand2 ==1 then
car2.pic = car2
end

if rand2 ==2 then
car3.pic = car3
end

if rand2 ==3 then
car4.pic = car4
end
end

function rands2()
rand3 = math.random(1,3)


if rand3 ==1 then
car2.pic = car2
end

if rand3 ==2 then
car3.pic = car3
end

if rand3 ==3 then
car4.pic = car4
end
end

function rands3()
rand4 = math.random(1,3)


if rand4 ==1 then
car2.pic = car2
end

if rand4 ==2 then
car3.pic = car3
end

if rand4 ==3 then
car4.pic = car4
end
end


XScrollPosition = 480

numberOfScrolls = 0

while true do
math.randomseed(os.time() )
rand=math.random(1,3)
random1 =math.random(20,25)
random2 =math.random(90,95)
random3 =math.random(192,197)

pad = Controls.read()
screen:clear()

oldx = player.x
oldy = player.y
screen:clear()

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
XScrollPosition = XScrollPosition - 10
if XScrollPosition < 0 then
XScrollPosition = XScrollPosition + 480
numberOfScrolls = numberOfScrolls + 1
end
end

if pad:up() then
character = car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:triangle() then
dofile("index1.lua")
end

if pad:square() then
Image:save("screenshot.png")
end

if pad:start() then
break
end


if rand ==1 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==2 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==3 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if car2.x <=0 then
car2.x =510
car2.y = random1
rands1()
end

if car3.x <=0 then
car3.x = 520
car3.y = random2
rands2()
end

if car4.x <=0 then
car4.x = 500
car4.y = random3
rands3()
end

screen:clear()

screen:blit(XScrollPosition, 0, road)

if XScrollPosition > 0 then
screen:blit(XScrollPosition - 480, 0, road)
else
screen:blit(XScrollPosition + 480, 0, road)
end

if numberOfScrolls > 30 then
dofile("eol.lua")
end

if player.x > 448 then
Player.x = 448
end
if player.x < 0 then
player.x = 0
end

if player.y > 240 then
player.y = 240
end
if player.y < 0 then
player.y = 0
end


detectCollision(player, car2)
detectCollision(player, car3)
detectCollision(player, car4)

-----------blit background and player------------

screen:blit(player.x, player.y, character)
screen:blit(car2.x, car2.y, car2.pic)
screen:blit(car3.x, car3.y, car3.pic)
screen:blit(car4.x, car4.y, car4.pic)
screen.flip()
screen.waitVblankStart()
end
-----------------------------------------------------------------

Any help will be much appreciated

gunntims0103
October 30th, 2006, 20:34
I dont think that your problem lies in your code i just think it has to do with the format of the png images change them and make sure that the encoding of these images are .png if you do this it should work.

splodger15
October 30th, 2006, 20:52
So i changed all my images to png

and i am getting this error now
------------------------------------------------------------------

error: SCRIPT.LUA:18: Image.load:error loading image
------------------------------------------------------------------

Can someone help me out with this

Zion
October 30th, 2006, 21:38
Make sure your image paths for that image on line 14 are corrrect and that the image is in the correct folder, trust me ive made that mistake loads of times :p

splodger15
October 30th, 2006, 22:02
Make sure your image paths for that image on line 14 are corrrect and that the image is in the correct folder, trust me ive made that mistake loads of times :p

Done that changed the paths to the correct places so that seems correct now

But now i am getting

-----------------------------------------------------------------

error:SCRIPT.LUA:213: bad argument #2 to 'blit' (image expected ,got nil)

yaustar
October 30th, 2006, 23:20
car1 is nil therefore character is nil. (look at the top of your code where you have "character = car1" ).

splodger15
October 31st, 2006, 17:06
What can i do to fix it

drEDN4wt
October 31st, 2006, 17:19
you havent declared car1

instead of;
player1=Image.load("images/car1.PNG")

use;
car1=Image.load("images/car1.PNG")
player1=car1

splodger15
October 31st, 2006, 17:31
I corrected that bit you said to but now i am getting
Can someone please help me out with this
------------------------------------------------------------------

error:SCRIPT.LUA:214: bad argument #2 to 'blit' (image expected ,got nil)

drEDN4wt
October 31st, 2006, 21:11
at a guess its because you havent declared the variable on line 214.

from the error msg it is trying to blit an image but the image doesn't exist.

find the image variable on line 214 and declare it

splodger15
October 31st, 2006, 21:18
Would i use it like this

------------------------------------------------------------------
car2=Image.load("images/car2.PNG")
car2=car2

drEDN4wt
October 31st, 2006, 21:21
as before.....

you havent declared road

instead of;
background=Image.load("images/road.PNG")

use;
road=Image.load("images/road.PNG")
background=road

maybe you dont need background at all.
do you ever forget where you put things or peoples names?

don't use car2=car2 ever

splodger15
October 31st, 2006, 21:47
Here is my script so far,but i seemed to get this error now:

--------------------------------------------------------------
error:script.LUA:6: attempt to call method 'width' (a nil value)
-----------------------------------------------------------------

-- Created by splodger15


----------detect other cars collision--------------
function detectCollision(player, opponent)
if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
screen.waitVblankStart(60)
dofile("menu.lua")
end
end

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
road=Image.load("images/road.PNG")
background=road
car1=Image.load("images/car1.PNG")
player1=car1
car2=Image.load("images/car2.PNG")
car3=Image.load("images/car3.PNG")
car4=Image.load("images/car4.PNG")

----------walls------------

wall1 = Image.createEmpty(480,2)
wall2 = Image.createEmpty(2,272)
wall3 = Image.createEmpty(2,272)
wall4 = Image.createEmpty(480,2)

wall1 = {x = 0, y = 0, height = wall1:height(), width = wall1:width() }
wall2 = {x = 450, y = 0, height = wall2:height(), width = wall2:width() }
wall3 = {x = 0, y = 0, height = wall3:height(), width = wall3:width() }
wall4 = {x = 0, y = 299, height = wall4:height(), width = wall4:width() }



player = {}
player.x = 250
player.y = 100
playerHeight = 63
playerWidth = 33

car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = car2

car3 = {}
car3.x = 228
car3.y = 20
car3Height = 63
car3Width = 33
car3.pic = car3

car4 = {}
car4.x = 28
car4.y = 20
car4Height = 63
car4Width = 33
car4.pic = car4

character = car1


------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)


if rand2 ==1 then
car2.pic = car2
end

if rand2 ==2 then
car3.pic = car3
end

if rand2 ==3 then
car4.pic = car4
end
end

function rands2()
rand3 = math.random(1,3)


if rand3 ==1 then
car2.pic = car2
end

if rand3 ==2 then
car3.pic = car3
end

if rand3 ==3 then
car4.pic = car4
end
end

function rands3()
rand4 = math.random(1,3)


if rand4 ==1 then
car2.pic = car2
end

if rand4 ==2 then
car3.pic = car3
end

if rand4 ==3 then
car4.pic = car4
end
end


XScrollPosition = 480

numberOfScrolls = 0

while true do
math.randomseed(os.time() )
rand=math.random(1,3)
random1 =math.random(20,25)
random2 =math.random(90,95)
random3 =math.random(192,197)

pad = Controls.read()
screen:clear()

oldx = player.x
oldy = player.y
screen:clear()

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
XScrollPosition = XScrollPosition - 10
if XScrollPosition < 0 then
XScrollPosition = XScrollPosition + 480
numberOfScrolls = numberOfScrolls + 1
end
end

if pad:up() then
character = car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:triangle() then
dofile("index1.lua")
end

if pad:square() then
Image:save("screenshot.png")
end

if pad:start() then
break
end


if rand ==1 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==2 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==3 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if car2.x <=0 then
car2.x =510
car2.y = random1
rands1()
end

if car3.x <=0 then
car3.x = 520
car3.y = random2
rands2()
end

if car4.x <=0 then
car4.x = 500
car4.y = random3
rands3()
end

screen:clear()

screen:blit(XScrollPosition, 0, road)

if XScrollPosition > 0 then
screen:blit(XScrollPosition - 480, 0, road)
else
screen:blit(XScrollPosition + 480, 0, road)
end

if numberOfScrolls > 30 then
dofile("eol.lua")
end

if player.x > 448 then
Player.x = 448
end
if player.x < 0 then
player.x = 0
end

if player.y > 240 then
player.y = 240
end
if player.y < 0 then
player.y = 0
end


detectCollision(player, car2)
detectCollision(player, car3)
detectCollision(player, car4)

-----------blit background and player------------

screen:blit(player.x, player.y, character)
screen:blit(car2.x, car2.y, car2.pic)
screen:blit(car3.x, car3.y, car3.pic)
screen:blit(car4.x, car4.y, car4.pic)
screen.flip()
screen.waitVblankStart()
end
------------------------------------------------------------------

yaustar
October 31st, 2006, 23:05
You are assigning an object to a member of itself:
car2=Image.load("images/car2.PNG") -- car2 is an image
car2 = {} -- car2 is no longer an image and now a table
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = car2 -- car2.pic is now car2. Major logic flaw here.

Zack3008
November 1st, 2006, 02:01
maybe put some stuff after(with all the "if"s and everything) "while true do"??(especially the "rand"s)

splodger15
November 1st, 2006, 16:39
How can i fix this

Thanks

yaustar
November 1st, 2006, 17:19
car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = Image.load("images/car2.PNG")

This will solve one of your problems.

splodger15
November 1st, 2006, 17:41
How many problems are there iam am still getting this :error:script.LUA:6: attempt to call method 'width' (a nil value)

================================================== =====

-- Created by splodger15


----------detect other cars collision--------------
function detectCollision(player, opponent)
if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
screen.waitVblankStart(60)
dofile("menu.lua")
end
end

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
road=Image.load("images/road.PNG")
background=road
car1=Image.load("images/car1.PNG")
player1=car1
car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = Image.load("images/car2.PNG")
car3=Image.load("images/car3.PNG")
car4=Image.load("images/car4.PNG")

----------walls------------

wall1 = Image.createEmpty(480,2)
wall2 = Image.createEmpty(2,272)
wall3 = Image.createEmpty(2,272)
wall4 = Image.createEmpty(480,2)

wall1 = {x = 0, y = 0, height = wall1:height(), width = wall1:width() }
wall2 = {x = 450, y = 0, height = wall2:height(), width = wall2:width() }
wall3 = {x = 0, y = 0, height = wall3:height(), width = wall3:width() }
wall4 = {x = 0, y = 299, height = wall4:height(), width = wall4:width() }



player = {}
player.x = 250
player.y = 100
playerHeight = 63
playerWidth = 33

car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = car2

car3 = {}
car3.x = 228
car3.y = 20
car3Height = 63
car3Width = 33
car3.pic = car3

car4 = {}
car4.x = 28
car4.y = 20
car4Height = 63
car4Width = 33
car4.pic = car4

character = car1


------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)


if rand2 ==1 then
car2.pic = car2
end

if rand2 ==2 then
car3.pic = car3
end

if rand2 ==3 then
car4.pic = car4
end
end

function rands2()
rand3 = math.random(1,3)


if rand3 ==1 then
car2.pic = car2
end

if rand3 ==2 then
car3.pic = car3
end

if rand3 ==3 then
car4.pic = car4
end
end

function rands3()
rand4 = math.random(1,3)


if rand4 ==1 then
car2.pic = car2
end

if rand4 ==2 then
car3.pic = car3
end

if rand4 ==3 then
car4.pic = car4
end
end


XScrollPosition = 480

numberOfScrolls = 0

while true do
math.randomseed(os.time() )
rand=math.random(1,3)
random1 =math.random(20,25)
random2 =math.random(90,95)
random3 =math.random(192,197)

pad = Controls.read()
screen:clear()

oldx = player.x
oldy = player.y
screen:clear()

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
XScrollPosition = XScrollPosition - 10
if XScrollPosition < 0 then
XScrollPosition = XScrollPosition + 480
numberOfScrolls = numberOfScrolls + 1
end
end

if pad:up() then
character = car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:triangle() then
dofile("index1.lua")
end

if pad:square() then
Image:save("screenshot.png")
end

if pad:start() then
break
end


if rand ==1 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==2 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==3 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if car2.x <=0 then
car2.x =510
car2.y = random1
rands1()
end

if car3.x <=0 then
car3.x = 520
car3.y = random2
rands2()
end

if car4.x <=0 then
car4.x = 500
car4.y = random3
rands3()
end

screen:clear()

screen:blit(XScrollPosition, 0, road)

if XScrollPosition > 0 then
screen:blit(XScrollPosition - 480, 0, road)
else
screen:blit(XScrollPosition + 480, 0, road)
end

if numberOfScrolls > 30 then
dofile("eol.lua")
end

if player.x > 448 then
Player.x = 448
end
if player.x < 0 then
player.x = 0
end

if player.y > 240 then
player.y = 240
end
if player.y < 0 then
player.y = 0
end


detectCollision(player, car2)
detectCollision(player, car3)
detectCollision(player, car4)

-----------blit background and player------------

screen:blit(player.x, player.y, character)
screen:blit(car2.x, car2.y, car2.pic)
screen:blit(car3.x, car3.y, car3.pic)
screen:blit(car4.x, car4.y, car4.pic)
screen.flip()
screen.waitVblankStart()
end

yaustar
November 1st, 2006, 18:18
car2, car3 and car4 .pics are not images. Therefore when you try and call the width() function from them, it is a nil value.

splodger15
November 1st, 2006, 18:35
Can someone please Explain how to fix this issue thanks

yaustar
November 1st, 2006, 22:09
car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = Image.load("images/car2.PNG")

This will solve one of your problems.
This IS your problem at the moment and the fix is above.

splodger15
November 2nd, 2006, 16:11
I have added that to my code already

-----------------------------------------------------------------
-- Created by splodger15


----------detect other cars collision--------------
function detectCollision(player, opponent)
if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
screen.waitVblankStart(60)
dofile("menu.lua")
end
end

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
road=Image.load("images/road.PNG")
background=road
car1=Image.load("images/car1.PNG")
player1=car1
car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = Image.load("images/car2.PNG")
car3=Image.load("images/car3.PNG")
car4=Image.load("images/car4.PNG")

jak66
November 2nd, 2006, 17:17
perhaps you have to use the code you used for car2 for car3 and car4 as well

splodger15
November 2nd, 2006, 18:14
perhaps you have to use the code you used for car2 for car3 and car4 as well

I am not sure

yaustar
November 2nd, 2006, 18:18
The problem that is you STILL have the code that overwrites the variable type of car2.pic here. It goes from an image to a table:

car2.pic = car2
And yes, you have to do it for car3 and car4 since the same mistake is duplicated there.

splodger15
November 2nd, 2006, 20:23
Thank you for helping me out with this yaustar

My game runs for a bit (5 seconds) then it comes up with this error

Error: SCRIPT.LUA:6: attempt to call method 'width' (a nil value)

------------------------------------------------------------------

-- Created by splodger15


----------detect other cars collision--------------
function detectCollision(player, opponent)
if (player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width()) and (player.y + character:height() > opponent.y) and (player.y < opponent.y + opponent.pic:height()) then
screen.waitVblankStart(60)
end
end

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
road=Image.load("images/road.PNG")
background=road
car1=Image.load("images/car1.PNG")
player1=car1
car2=Image.load("images/car2.PNG")
car3=Image.load("images/car3.PNG")
car4=Image.load("images/car4.PNG")

----------walls------------

wall1 = Image.createEmpty(480,2)
wall2 = Image.createEmpty(2,272)
wall3 = Image.createEmpty(2,272)
wall4 = Image.createEmpty(480,2)

wall1 = {x = 0, y = 0, height = wall1:height(), width = wall1:width() }
wall2 = {x = 450, y = 0, height = wall2:height(), width = wall2:width() }
wall3 = {x = 0, y = 0, height = wall3:height(), width = wall3:width() }
wall4 = {x = 0, y = 299, height = wall4:height(), width = wall4:width() }



player = {}
player.x = 250
player.y = 100
playerHeight = 63
playerWidth = 33

car2 = {}
car2.x = 128
car2.y = 90
car2Height = 63
car2Width = 33
car2.pic = Image.load("images/car2.PNG")

car3 = {}
car3.x = 228
car3.y = 90
car3Height = 63
car3Width = 33
car3.pic = Image.load("images/car3.PNG")

car4 = {}
car4.x = 28
car4.y = 20
car4Height = 63
car4Width = 33
car4.pic = Image.load("images/car4.PNG")

character = car1


------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)


if rand2 ==1 then
car2.pic = car2
end

if rand2 ==2 then
car3.pic = car3
end

if rand2 ==3 then
car4.pic = car4
end
end

function rands2()
rand3 = math.random(1,3)


if rand3 ==1 then
car2.pic = car2
end

if rand3 ==2 then
car3.pic = car3
end

if rand3 ==3 then
car4.pic = car4
end
end

function rands3()
rand4 = math.random(1,3)


if rand4 ==1 then
car2.pic = car2
end

if rand4 ==2 then
car3.pic = car3
end

if rand4 ==3 then
car4.pic = car4
end
end


XScrollPosition = 480

numberOfScrolls = 0

while true do
math.randomseed(os.time() )
rand=math.random(1,3)
random1 =math.random(20,25)
random2 =math.random(90,95)
random3 =math.random(192,197)

pad = Controls.read()
screen:clear()

oldx = player.x
oldy = player.y
screen:clear()

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
XScrollPosition = XScrollPosition - 10
if XScrollPosition < 0 then
XScrollPosition = XScrollPosition + 480
numberOfScrolls = numberOfScrolls + 1
end
end

if pad:up() then
character = car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:triangle() then
dofile("index1.lua")
end

if pad:square() then
Image:save("screenshot.png")
end

if pad:start() then
break
end


if rand ==1 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==2 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if rand ==3 then
car2.x = car2.x -10
car3.x = car3.x-10
car4.x = car3.x-10
end

if car2.x <=0 then
car2.x =510
car2.y = random1
rands1()
end

if car3.x <=0 then
car3.x = 520
car3.y = random2
rands2()
end

if car4.x <=0 then
car4.x = 500
car4.y = random3
rands3()
end

screen:clear()

screen:blit(XScrollPosition, 0, road)

if XScrollPosition > 0 then
screen:blit(XScrollPosition - 480, 0, road)
else
screen:blit(XScrollPosition + 480, 0, road)
end

if numberOfScrolls > 30 then
dofile("eol.lua")
end

if player.x > 448 then
Player.x = 448
end
if player.x < 0 then
player.x = 0
end

if player.y > 240 then
player.y = 240
end
if player.y < 0 then
player.y = 0
end


detectCollision(player, car2)
detectCollision(player, car3)
detectCollision(player, car4)

-----------blit background and player------------

screen:blit(player.x, player.y, character)
screen:blit(car2.x, car2.y, car2.pic)
screen:blit(car3.x, car3.y, car3.pic)
screen:blit(car4.x, car4.y, car4.pic)
screen.flip()
screen.waitVblankStart()
end

drEDN4wt
November 2nd, 2006, 21:14
Error: SCRIPT.LUA:6: attempt to call method 'width' (a nil value)

the 6 refers to line 6
use an editor the shows the line numbers down the left margin, such as emeditor

its trying to look up :width so its either
character:width()
or opponent.pic:width()

and i dont see a declaration for opponent

oh i do now.. :s

at the moment you are using

character:width()........... value is a record in a table
opponent.pic:width......... value is a record in a table in a table
car2Width....................... just a value

you need to decide on which way your going to store widths and change them

splodger15
November 2nd, 2006, 21:32
(player.x + character:width() > opponent.x) and (player.x < opponent.x + opponent.pic:width())

Could it be the bit i highlighted bold
The close bracket on the end

drEDN4wt
November 2nd, 2006, 21:38
no its not the bracket , its what yaustar explains above

try deleting
------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)


if rand2 ==1 then
car2.pic = car2
end

if rand2 ==2 then
car3.pic = car3
end

if rand2 ==3 then
car4.pic = car4
end
end

function rands2()
rand3 = math.random(1,3)


if rand3 ==1 then
car2.pic = car2
end

if rand3 ==2 then
car3.pic = car3
end

if rand3 ==3 then
car4.pic = car4
end
end

function rands3()
rand4 = math.random(1,3)


if rand4 ==1 then
car2.pic = car2
end

if rand4 ==2 then
car3.pic = car3
end

if rand4 ==3 then
car4.pic = car4
end
end

splodger15
November 2nd, 2006, 21:49
no its not the bracket , its what yaustar explains above

try deleting

I deleted the bit you said to delete but now i am getting.

Also is there a text editor that has the numbers down the side so i can find it easier

------------------------------------------------------------------
error: SCRIPT.LUA:144: attempt to call global 'rands1' (a nil value)

drEDN4wt
November 2nd, 2006, 22:02
http://www.emurasoft.com/
emeditor

and youll have to put back in
rand2=
rand3=
etc

and put back in

------------------player sprite loading--------------

function rands1()
rand2 = math.random(1,3)
end

function rands2()
rand3 = math.random(1,3)
end

function rands3()
rand4 = math.random(1,3)
end

yaustar
November 3rd, 2006, 12:59
http://notepad-plus.sourceforge.net/uk/about.php

Notepad++. Free, Open source and it just plain rocks.

splodger15
November 3rd, 2006, 16:36
It is working now thanking you everyone for your help