Jump to content

Выдаёт ошибку


Recommended Posts

Собственно есть двумерный массив

WeatherInWorld = {},{} 

А одном месте выполняю этот код

WeatherInWorld[2][1] = CreateAdjacentWeather(WeatherInWorld[1][4], month) 
WeatherInWorld[2][2] = CreateAdjacentWeather(WeatherInWorld[2][1], month) 
WeatherInWorld[2][3] = CreateAdjacentWeather(WeatherInWorld[2][2], month) 
WeatherInWorld[2][4] = CreateAdjacentWeather(WeatherInWorld[2][3], month) 

Вот Function CreateAdjacentWeather

function CreateAdjacentWeather(x, y) 
             if(y == 1) 
             then 
                       if(x == 1) 
                       then  
                                 return 1 
                       else 
                                 return 0 
                       end 
             else 
                       return 0 
             end 
end 

Суть функции думаю поняли (в реальности она такая же,только чуть больше условных конструкций)

В итоге ошибка

attempt to index field ' ' (a nil value) 

на

WeatherInWorld[2][1] = CreateAdjacentWeather(WeatherInWorld[1][4], month) 
WeatherInWorld[2][2] = CreateAdjacentWeather(WeatherInWorld[2][1], month) 
WeatherInWorld[2][3] = CreateAdjacentWeather(WeatherInWorld[2][2], month) 
WeatherInWorld[2][4] = CreateAdjacentWeather(WeatherInWorld[2][3], month) 

Что исправить надо и как?И,вообще в чём косяк?

Link to comment
WeatherInWorld[2][1] = CreateAdjacentWeather(WeatherInWorld[2][4], month) 
WeatherInWorld[2][2] = CreateAdjacentWeather(WeatherInWorld[2][1], month) 
WeatherInWorld[2][3] = CreateAdjacentWeather(WeatherInWorld[2][2], month) 
WeatherInWorld[2][4] = CreateAdjacentWeather(WeatherInWorld[2][3], month) 

пальцем в небо. :roll:

Link to comment
WeatherInWorld[2][1] = CreateAdjacentWeather(WeatherInWorld[2][4], month) 
WeatherInWorld[2][2] = CreateAdjacentWeather(WeatherInWorld[2][1], month) 
WeatherInWorld[2][3] = CreateAdjacentWeather(WeatherInWorld[2][2], month) 
WeatherInWorld[2][4] = CreateAdjacentWeather(WeatherInWorld[2][3], month) 

пальцем в небо. :roll:

Ошибка явно не в этом.Тут всё правильно.Именно WeatherInWorld[1][4] надо,ибо это погода вечера прошлого дня.

Link to comment

Всё,решил.Проблема была в моей криворукости.Я неправильно объявил двумерный массив.

Вместо

WeatherInWorld = {},{} 

надо было

WeatherInWorld = {} 

и

 for i=1, 3 do 
         WeatherInWorld[i] = {} 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...