Jump to content




[Lua] [Error] config:11: attempt to concatenate string and nil

help

7 replies to this topic

#1 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 27 November 2012 - 09:02 AM

CC version 1.41

Code:
write "1: "
a = read()
w "2: "
b = read()
file = fs.open("testy\1.os\config", "a")
file.write(a)
file.write(B)/>/>/>
fileR = fs.open("testy\1.os\config", "r")
print ("1: "..fileR.readLine("1"))
print ("2: "..fileR.readLine("2"))

Code is in polish because im from poland :P

#2 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 27 November 2012 - 09:50 AM

There is only 10 lines, how an error can occur in the line 11 ?

#3 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 27 November 2012 - 10:13 AM

surely the readLine function requires numeric input, not strings

write("1: ")
a = read()
write("2: ")
b = read()
file = fs.open("testy\1.os\config", "a")
file.write(a)
file.write(B)/>
fileR = fs.open("testy\1.os\config", "r")
print ("1: "..fileR.readLine(1))
print ("2: "..fileR.readLine(2))

I am not sure as I use the io API. here is how it would look if you used it

write("1: ")
a = read()
write("2: ")
b = read()
file = io.open("testy\1.os\config", "w")
file:write(a)
file:write(B
fileR = io.open("testy\1.os\config", "r")
print ("1: "..fileR:read())
print ("2: "..fileR:read())

also please make sure that the testy\1.os directory exists or it will be unable to create the file. you can add code to create it if it does not exist

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,458 posts

Posted 27 November 2012 - 02:53 PM

readLine() does not take arguments.

#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 27 November 2012 - 03:49 PM

ahh. didn't know that. thanks.... I'm such a n00b sometimes

#6 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 27 November 2012 - 08:28 PM

View PostLyqyd, on 27 November 2012 - 02:53 PM, said:

readLine() does not take arguments.
Thanks but then how to set what a line read? term.setCursorPos(x,y)

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 27 November 2012 - 08:37 PM

Nah. Just do multiple instances of readLine()
Each time you call it, the function will read the next line in the file.
local line1 = fileR.readLine()
local line2 = fileR.readLine()
--et cetera


#8 00frugo

  • New Members
  • 1 posts

Posted 11 May 2013 - 06:17 AM

View PostKaoS, on 27 November 2012 - 10:13 AM, said:

surely the readLine function requires numeric input, not strings

write("1: ")
a = read()
write("2: ")
b = read()
file = fs.open("testy\1.os\config", "a")
file.write(a)
file.write(B)/>/>/>/>/>
fileR = fs.open("testy\1.os\config", "r")
print ("1: "..fileR.readLine(1))
print ("2: "..fileR.readLine(2))

I am not sure as I use the io API. here is how it would look if you used it

write("1: ")
a = read()
write("2: ")
b = read()
file = io.open("testy\1.os\config", "w")
file:write(a)
file:write(B
fileR = io.open("testy\1.os\config", "r")
print ("1: "..fileR:read())
print ("2: "..fileR:read())

also please make sure that the testy\1.os directory exists or it will be unable to create the file. you can add code to create it if it does not exist
thanks! This is a good way to save for my program:
term.clear()
local gra = "kontynuacja"
write "GRA: Wpisz nowa/kontynuacja: "
input = read()
if gra == input then
  write "kod z1 "
  input = read()
  local zycia = input
   write "kod h1 "
   input = read()
   local dom = input
	 write "kod dr1 "
	 input = read()
	 local drewno = input
	   write "kod k1 "
	   input = read()
	   local kamien = input
		 write "kod l1 "
		 input = read()
		 local liscie = input
		   write "kod p1: "
		   input = read()
		   local liscie = input
			  write "kod k2: "
			  input = read()
			  local kwiaty = input
				write "kod l2: "
				input = read()
				local lopata = input
				  write "kod w1: "
				  input = read()
				  local wegiel = input
					write "kod z2: "
					input = read()
					local zelazo = input
					  write "kod z3: "
					  input = read()
					  local zloto = input
						write "kod d1: "
						input = read()
						local diament = input
						  write "kod kop: "
						  input = read()
						  local kop = input
							write "kod top: "
							input = read()
							local top = input
						  
else
local zycia = 10
local dom = 0
local drewno = 0
local kamien = 0
local liscie = 0
local patyki = 3  
local kwiaty = 0
local lopata = 10
local wegiel = 0
local zelazo = 0
local zloto = 0
local diament = 0
local kop = 0
local top = 0
end
if term.isColour() then
r = colours.red
w = colours.white
l = colours.lime
y = colours.yellow
b = colours.black
else
r = colours.white
w = colours.black
l = colours.white
y = colours.white
b = colours.white
end
term.clear()
term.setCursorPos(2,2)
	print "HAMTAROWA WYSPA /na CraftOS/"
print "HISTORIA"
print "Hamtaro chcial przyniesc na Hamtarowa Wyspe nowa rzecz. Wyplynal i rozbil sie na dziwnej wyspie nazwal ja: \n Pozawysp."

local czas = 12
local czasI = "czas"
local pozycja = 1
local idzI = "idz plaza"
local idzdom = "idz dom"
local exit = "exit"
local pomoc = "pomoc"
local spanie = "spanie"
local buduj = "buduj dom"
local budujI = "buduj dom z drewno"
local budujII = "buduj dom z kamien"
local budujIII = "buduj dom z siano"
local tworz = "tworz"
local kopalnia = "kopalnia"
local rab = "rab drzewo"
local inwentarz = "inwentarz"
local save = "zapisz"
local tworzI = "tworz kilof"
local tworzII = "tworz topor"
local tworzIII = "tworz patyki"
local tworzIV = "tworz tratwe"
local zyciaI = "zycia"

i = 5
repeat
term.setTextColour( y )
write "Hamtaro> "
term.setTextColour( w )
input = read()
if tworz == input then
print "Sposob uzycia: \n tworz <kilof / topor / patyki / tratwe>"
else
end
if tworzI == input then
print "TWORZENIE: \n Wymagania: \n  3xpatyki"
if patyki > 2 then
textutils.slowPrint( "tworzenie..." )
patyki = patyki - 3
kop = kop + 50
else
term.setTextColour( r )
print "BRAK MATERIALOW"
term.setTextColour( w )
end
else
end
if tworzII == input then
print "TWORZENIE\n Wymagania: \n  2xpatyki"
if patyki > 1 then
textutils.slowPrint( "Tworzenie..." )
patyki = patyki - 2
top = top + 50
else
term.setTextColour( r )
print "BRAK MATERIALOW"
term.setTextColour( w )
end
else
end
if tworzIII == input then
print "TWORZENIE\n Wymagania \n  1xdrewno"
if drewno > 0 then
textutils.slowPrint( "Tworzenie..." )
drewno = drewno - 1
patyki = patyki + 3
else
end
else
end
if tworzIV == input then
print "TWORZENIE\n Wymagania \n  5xdrewno\n  4xdiament \n 2xzelazo"
	if drewno > 4 then
	print "starczy drewna..."
		if diament > 3 then
		print "starczy diamentow..."
			if zelazo > 1 then
			print "starczy zelaza..."
			print "STARCZY WSZYSTKIEGO"
			textutils.slowPrint( "TWORZENIE...\nBUDOWANIE...\nWIAZANIE...\nMOCOWANIE...")
			drewno = drewno - 5
			diament = diament - 4
			zelazo = zelazo - 2
			term.setTextColour( l )
			print "POWIODLO SIE!!!"
			term.setTextColours( b )
			sleep( 5 )
			term.clear()
			term.setCursorPos(5,5)
			print ("								  ")
			print ("			 WYGRANA			  ")
			print ("PRZEDMIOTY:					   ")
			print (" SUROWCE:						 ")
			print ("drewno x"..drewno..",					   ")
			print ("kamien x"..kamien.." i inne				  ")
			print (" NARZEDZIA:					   ")
			print ("topor "..top.." pz, kilof "..kop.."pz	  ")
			print ("Hamtaro wyplynal z Pozawyspu...   ")
			print ("Poplynal do Polski...			 ")
			print ("I wrocil...					   ")
			sleep(30)
			os.shutdown()
			else
			term.setTextColour( r )
			print "BRAK MATERIALOW"
			term.setTextColour( w )
			end
		else
		term.setTextColour( r )
		print "BRAK MATERIALOW"
		term.setTextColour( w )
		end
	term.setTextColour( r )
	print "BRAK MATERIALOW"
	term.setTextColour( w )  
	end
term.setTextColour( r )
print "BRAK MATERIALOW"
term.setTextColour( w )  
end
if czasI == input then
if czas < 1 then
else
czas = czas - 1
end
print (czas)
else
end
if zyciaI == input then
print (zycia)
czas = czas - 1
else
end
if idzI == input then
print "plaza"
pozycja = pozycja + 1
else
end
if idzdom == input then
pozycja = pozycja - 1
print ("Sila domu: "..dom.." hp (0 ozanacza, ze dom nie istnieje)")
else
end
if pomoc == input then
write "POMOC \nHamtarowa wyspa Pozawysp 1.5 \n KOMENDY: "
term.setTextColour( y )
write "idz, pomoc, buduj, kopalnia, rab <drzewo>, inwentarz, czas (pokazuje godzine), spanie, zycia, tworz <kilof, topor, patyki> "
term.setTextColour( w )
write "ZROBIONE PRZEZ: Dominik Drozak "
term.setTextColour( r )
print "WPISZ 'exit', BY WYJSC Z GRY"
term.setTextColour( w )
else
end
if buduj == input then
print "Sposoby uzycia: \n buduj dom z drewno, \n buduj dom z kamien \n buduj dom z siano"
else
end

if budujI == input then
print "Budowanie: \n WYMAGANIA: \n  drewno x20."
if drewno > 20 then
drewno = drewno - 20
dom = dom + 50
else
term.setTextColour( r )
print "BRAK MATERIALOW"
term.setTextColour( w )
end
end
if budujII == input then
print "Budowanie: \n WYMAGANIA: \n  kamien x40."
if kamien > 40 then
kamien = kamien - 40
dom = dom + 100
else
term.setTextColour( r )
print "brak materialow"
term.setTextColour( w )
end
else
end
if budujIII == input then
print "Budowanie: \n WYMAGANIA: \n  tak zwana lopata."
if lopata > 1 then
dom = dom + 05
lopata = lopata - 1
else
term.setTextColour( r )
print "BRAK TAK ZWANEJ LOPATY"
term.setTextColour( w )
end
else
end
if spanie == input then
if dom < 1 then
term.setTextColour( r )
print "nie mozesz spac bez domu!"
term.setTextColour( w )
else
if czas > 20 then
textutils.slowPrint( "spanie..." )
czas = czas + 10
zycia = zycia + 6
print " Jezeli pokaze ci sie, ze jest noc i, ze widzisz potwory to jest nie prawda"
else
term.setTextColour( r )
print " nie mozesz spac!"
term.setTextColour( w )
end
end
else
end
if kopalnia == input then
textutils.slowPrint "kopanie..."
if kop > 0 then
kop = kop - 1
kamien = kamien + 30
zelazo = zelazo + 5
zloto = zloto + 2
diament = diament + 1
print "WYKOPANO: \n 30xkamien, 5xzelazo, 2xzloto, 1x diament"
else
kamien = kamien + 10
print "WYKOPANO: \n 10xkamien"
end
else
end
if rab == input then
textutils.slowPrint "Rabanie drzew..."
if top > 0 then
top = top - 1
drewno = drewno + 10
liscie = liscie + 5
print "ZRABANO: \n 2xdrzewa (+ 10 drewno, + 5 liscie) "
else
drewno = drewno + 5
print "ZRABANO: \n 1xdrzewo (+ 5 drewno, brak sprzetu, nie udalo sie wziasc lisci."
end
else
end
if inwentarz == input then
print ("drewno x"..drewno..", kamien x"..kamien..", zelazo x"..zelazo..", diament x"..diament.."<SUROWCE>| topor "..top.."zp (punkty zuzycia), kilof "..kop.." pz <nazedzia>| liscie x"..liscie..", patyki x"..patyki..", kwiaty "..kwiaty.."<inne>")
end
if exit == input then
term.setTextColour( y )
print ("kody: z1 "..zycia.."\n h1 "..dom.."\n dr1 "..drewno.."\n k1 "..kamien.."\n l1 "..liscie.."\n p1 "..patyki.."\n k2 "..kwiaty.."\n l2 "..lopata.."\n w1 "..wegiel.."\n z2 "..zelazo.."\n z3"..zloto.."\n d1 "..diament.."\n kop "..kop.."\n top "..top.." <wpisz je przy wlaczaniu hw>")
write "Dowidzenia!"
input = read()
os.shutdown()
else
end
czas = czas + 1
if czas > 21 then
term.setTextColour( r )
print "Widzisz potwory!"
zycia = zycia - 1
print "jest noc!"
term.setTextColour( w )
else
end
if czas > 24 then
czas = czas - 24
else
end
if czas < 4 then
term.setTextColour( r )
print "jest noc!"
print "widzisz potwory!"
term.setTextColour( w )
else
end
if zycia < 1 then
term.setTextColour( r )
print "N I E   Z Y J E S Z !"
sleep(1)
print "K O N I E C   G R Y !"
sleep(5)
os.shutdown()
else
end

  i = i + 0,5
until i > 999999
sleep(1)
I made a statement that the program creates the code writing, and then you have to type it, but it shows me that what we talk about.

I am of Polish as the author of this thread.

I will see the answer as to why I show this message.

It just so happens that I have a problem with that chicken pounding in my bow, teleport up and so on. Maybe he wants to help me ... :D
translated by google translate polish>english





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users