[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Undefined method '[]' I dont know why.

Nation, Carey

11/3/2008 7:36:00 PM

Hi,
Well, it's really telling you that something that you're indexing into
is nil. Not sure which of the things in that big assignment is the nil
one, but something there is.

HTH,=20
Carey


-----Original Message-----
From: mati829@gmail.com [mailto:mati829@gmail.com]=20
Sent: Monday, November 03, 2008 2:17 PM
To: ruby-talk ML
Subject: Undefined method '[]' I dont know why.

Hello , I have problem with my script.

/////////////this function return true or false
def moznazbudowac?(co,sesja,stan)
budynek =3D ""
catch(:redo) do
case co
when 1
budynek =3D "Kopalnia metalu"
when 2
budynek =3D "Kopalnia krysztalu"
when 3
budynek =3D "Kopalnia deuteru"
end
end
poziom =3D stan[budynek] # 11
poziom =3D poziom.to_i
surowce_pods =3D bazadanych(co) #output
[60,15,0,1.5]
surowce_potrz =3D [0,0,0,0]
surowce_potrz[0] =3D surowce_pods[0].to_i
*surowce_pods[3].to_i**(poziom-1)#Error
[.....]# further part of script
//////////////////////


Error : Undefined method '[]' for nil:NilClass <NoMethodError>
I try to modify script but dont know how fix this error.

a =3D moznazbudowac?(1,sesja,stan) // this is working

But when i execute this
sesja =3D sesja()
stan =3D skaner ()
kolejka() return array i was testing with array [1]
test_kolejki =3D kolejka()
kolejkowanie(test_kolejki,sesja,stan)#error
I have error in function kolejkowanie() and i line above and in function
moznazbudowac?.

/////////////////
def kolejkowanie(kolejka,sesja,stan)
dlugosc =3D kolejka.length
dlugosc -=3D1
nr =3D 0
while nr<=3Ddlugosc
zbudowano =3D 0
while zbudowano =3D=3D 0
if moznazbudowac?(kolejka[nr],sesja,stan) =3D=3D true then#error
zbuduj(kolejka[nr],sesja)
kolejka.pop
nr +=3D1
zbudowano =3D 1
else
"Nie starczy surowcow"
end
end

end

end
///////////////////
--=20
Posted via http://www.ruby-....


1 Answer

Mateusz Ga

11/3/2008 7:59:00 PM

0

Thx for help. Now i see what's wrong:
if moznazbudowac?(kolejka[nr],sesja,stan) == true

kolejka does error. I will fix this tomorrow.




--
Posted via http://www.ruby-....