 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Tue Nov 08, 2005 9:25 am Post subject: whats wrong with my code? NOOB |
|
|
I just started the LUA thing about a month ago and am still getting the hang of it. When I execute this code: (I know its long)
| Code: | black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
newcwd = "ms0:/"
oldpad = Controls.read()
number=1
function openfile()
text = {}
i=1
cheatfile = number .. ".txt"
start=0
startx=0
cross=0
mode1=1
mode2=0
exit2=false
file = io.open(cheatfile,"r")
line=file:read("*l")
while line~=nil do
text[i]=line
i=i+1
line=file:read("*l")
end
if i>35 then
k=35
else
k=i
end
end
function textreader()
screen:clear(Color.new(0, 0, 0))
openfile()
while exit2==false do
pad = Controls.read()
if pad:select() then
exit2=true
end
if pad:cross() then
cross=10
elseif pad:circle() then
cross=34
else
cross=1
end
if pad:down() then
start=start+cross
if i<k+start then
start=i-k
end
elseif pad:up() then
start=start-cross
if start<0 then
start=0
end
end
if pad:right() then
startx=startx+cross
elseif pad:left() then
startx=startx-cross
if startx<0 then
startx=0
end
end
if oldpad ~= pad then
if pad:r() then
number = number + 1
if number > 3 then
number=1
end
openfile()
elseif pad:l() then
number = number - 1
if number < 1 then
number=3
end
openfile()
end
oldpad = pad
end
screen:clear(white)
for j = 1,k-1 do
if mode2==0 then
screen:print(0, 8*(j-1), string.format("%s",string.sub(text[j+start],startx,(string.len(text[j+start])-mode1))), black)
else
screen:print(0, 8*(j-1), string.format("%04d",j+start), black)
screen:print(36, 8*(j-1), string.format("%s",string.sub(text[j+start],startx,(string.len(text[j+start])-mode1))), black)
end
end
screen.waitVblankStart()
screen.flip()
screen.waitVblankStart(3)
end
end
while true do
textreader()
end |
It works fine at first. Once I press the r or l trigger 10 times, i get an error. The error is ":21: attempt to index global 'file' (a nil value)" It is always 10 times. This makes no since. If you execute it, you must make 3 files name 1.txt 2.txt and 3.txt and put random text in it for a test.
thanks in advance
darklitch |
|
| Back to top |
|
 |
chaos
Joined: 10 Apr 2005 Posts: 135
|
Posted: Tue Nov 08, 2005 2:36 pm Post subject: |
|
|
this is probably the 4th topic on this error.. basically, you need to close your files when you're done reading from them. if you have more than 10 files open, lua will crash.. _________________ Chaosmachine Studios: High Quality Homebrew. |
|
| Back to top |
|
 |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Wed Nov 09, 2005 4:06 am Post subject: |
|
|
| wow I would never have thought of that. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|