[Question]Where is the bug?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
nikneym
Citizen
Posts: 56
Joined: Sat Mar 09, 2013 1:22 pm
Contact:

[Question]Where is the bug?

Post by nikneym »

Code: Select all

anadosyam="oku.gr";
ac=io.open(anadosyam, "r+");

while true do
  actir=ac.read(ac, "*a");
  
  if not line then
    break;
  end
end

acilacakdosya=actir;
  acilacak=io.open(acilacakdosya,"r");

  while true do
    kodlar=acilacak.read(acilacak, "*a");

    if not line then
      break;
    end
  end
İt prints:

Code: Select all

Program starting as '"lua" -e "xpcall(function() io.stdout:setvbuf('no'); require('mobdebug').loop('nikneym-MS-7507',8172) end,function(err) print(debug.traceback(err)) end)"'.
Program 'lua' started in '/home/nikneym/Desktop/Html5-OyunMotoru/html5' (pid: 3271).
Debugging session started in '/home/nikneym/Desktop/Html5-OyunMotoru/html5/'.
Debugging session completed (traced 0 instructions).
Program completed in 0,39 seconds (pid: 3271).
main.lua:29: attempt to index global 'acilacak' (a nil value)
stack traceback:
	main.lua:29: in main chunk

Where is the bug?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [Question]Where is the bug?

Post by Plu »

My guess would be that the program either failed to read a filename into "actir", or the file it tries to read does not exist. Try getting the error from io.open and printing it:

Code: Select all

acilacak, error =io.open(acilacakdosya,"r");
if acilacak == nil then
  print( error )
end
Or something along those lines. See also http://www.lua.org/pil/21.2.html
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: [Question]Where is the bug?

Post by Robin »

This might not directly be involved in the error you get, but the following occurs twice in your code:

Code: Select all

  if not line then
    break;
  end
The problem is, you never assign anything to line. It seems you copied that from somewhere else. I would replace

Code: Select all

while true do
  actir=ac.read(ac, "*a");
 
  if not line then
    break;
  end
end
by

Code: Select all

actir=ac.read(ac, "*a");
and do the same for the other bit.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests