Undefined method '[]' I dont know why.

M

Mateusz Ga

Hello , I have problem with my script.

/////////////this function return true or false
def moznazbudowac?(co,sesja,stan)
budynek = ""
catch:)redo) do
case co
when 1
budynek = "Kopalnia metalu"
when 2
budynek = "Kopalnia krysztalu"
when 3
budynek = "Kopalnia deuteru"
end
end
poziom = stan[budynek] # 11
poziom = poziom.to_i
surowce_pods = bazadanych(co) #output
[60,15,0,1.5]
surowce_potrz = [0,0,0,0]
surowce_potrz[0] = 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 = moznazbudowac?(1,sesja,stan) // this is working

But when i execute this
sesja = sesja()
stan = skaner ()
kolejka() return array i was testing with array [1]
test_kolejki = 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 = kolejka.length
dlugosc -=1
nr = 0
while nr<=dlugosc
zbudowano = 0
while zbudowano == 0
if moznazbudowac?(kolejka[nr],sesja,stan) == true then#error
zbuduj(kolejka[nr],sesja)
kolejka.pop
nr +=1
zbudowano = 1
else
"Nie starczy surowcow"
end
end

end

end
///////////////////
 
M

Mateusz Ga

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

kolejka does error. I will fix this tomorrow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top