• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Linux Bad argument ipairs isInArray

Calon

Experienced Member
Joined
Feb 6, 2009
Messages
1,070
Reaction score
21
Hello, im using 0.3.7SVN but there is something wrong here..

Code:
[11:40:41.080] [Error - GlobalEvent Interface]
[11:40:41.080] data/globalevents/scripts/raid.lua:onThink
[11:40:41.080] Description:
[11:40:41.080] data/lib/050-function.lua:4: bad argument #1 to 'ipairs' (table expected, got nil)
[11:40:41.080] stack traceback:
[11:40:41.080]  [C]: in function 'ipairs'
[11:40:41.080]  data/lib/050-function.lua:4: in function 'isInArray'
[11:40:41.080]  data/globalevents/scripts/raid.lua:158: in function <data/globalevents/scripts/raid.lua:153>
[11:40:41.080] [Error - GlobalEvents::think] Couldn't execute event: raids


im getting this while i got in my lib-functions

LUA:
function isInArray(array, value, caseSensitive)
	if(caseSensitive == nil or caseSensitive == false) and type(value) == "string" then
		local lowerValue = value:lower()
		for _, _value in ipairs(array) do
			if type(_value) == "string" and lowerValue == _value:lower() then
				return true
			end
		end
	else
		for _, _value in ipairs(array) do
			if (value == _value) then return true end
		end
	end

	return false
end

and here is my raid
LUA:
--[[
- hour should be exact SERVER hour
- to do the raid at clock 00 minutes 00
- to do the raid at exaxt date use type "exact"
- to do the raid weekly use type "weekly"
- days names are used only for weekly type and should be 
- "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"
- also should be inside a array -> {}
]]

local raids =
	{
		[1] = 
			{
				name = 'Morgaroth',
				type = 'weekly',
				days = {'saturday'},
				hour = 22,
				minu = 00
			},
		[2] = 
			{
				name = 'Zulazza the Corruptor',
				type = 'weekly',
				days = {'wednesday'},
				hour = 19,
				minu = 00
			},
		[3] = 
			{
				name = 'RatsThais',
				type = 'weekly',
				days = {'monday'},
				hour = 20,
				minu = 00
			},
		[4] = 
			{
				name = 'Demodras',
				type = 'weekly',
				days = {'saturday'},
				hour = 15,
				minu = 00
			},
		[5] = 
			{
				name = 'Ferumbras',
				type = 'weekly',
				date = {'friday'},
				hour = 22,
				minu = 00
			},
		[6] = 
			{
				name = 'Ghazbaran',
				type = 'weekly',
				date = {'thursday'},
				hour = 20,
				minu = 00
			},
		[7] = 
			{
				name = 'Horned Fox',
				type = 'weekly',
				days = {'monday'},
				hour = 15,
				minu = 00
			},
		[8] = 
			{
				name = 'Necropharus',
				type = 'weekly',
				days = {'monday'},
				hour = 19,
				minu = 00
			},
		[9] = 
			{
				name = 'Orshabaal',
				type = 'weekly',
				date = {'sunday'},
				hour = 19,
				minu = 00
			},
		[10] = 
			{
				name = 'Scarabs',
				type = 'weekly',
				days = {'sunday'},
				hour = 19,
				minu = 00
			},
		[11] = 
			{
				name = 'Old Widow',
				type = 'weekly',
				days = {'tuesday'},
				hour = 19,
				minu = 00
			},
		[12] = 
			{
				name = 'Aniversary',
				type = 'weekly',
				days = {'friday'},
				hour = 18,
				minu = 00
			},
		[13] = 
			{
				name = 'Tiquandas Revenge',
				type = 'weekly',
				days = {'tuesday'},
				hour = 15,
				minu = 00
			},
              [14] = 
			{
				name = 'Vampire',
				type = 'weekly',
				days = {'thursday'},
				hour = 20,
				minu = 00
			},
		[15] = 
			{
				name = 'Demons',
				type = 'weekly',
				days = {'saturday'},
				hour = 19,
				minu = 00
			},
		[16] = 
			{
				name = 'warlocks',
				type = 'weekly',
				days = {'tuesday'},
				hour = 21,
				minu = 00
			},
		[17] = 
			{
				name = 'mutated',
				type = 'weekly',
				days = {'wednesday'},
				hour = 15,
				minu = 00
			}
	}
	
local last_execsutes = {}

function onThink(interval, lastExecution, thinkInterval)
    local static_time = os.time()
    for k, raid in ipairs(raids) do
        if (raid.type == 'weekly') then
            local day = os.date("%A", static_time):lower()
            if isInArray(raid.days, day) then
                local hour = tonumber(os.date("%H", static_time))
                if (raid.hour == hour) then
                    local minute = tonumber(os.date("%M", static_time))
                    if (raid.minu == minute) then
                        local day_number = tonumber(os.date("%d", static_time))
                        if (last_execsutes[k] ~= day_number) then
                            last_execsutes[k] = day_number
                            doExecuteRaid(raid.name)
                        end
                    end
                end
            end
        elseif (raid.type == 'exact') then
            local month = tonumber(os.date("%m", static_time))
            if (raid.date.month == month) then
                local day = tonumber(os.date("%d", static_time))
                if (raid.date.day == day) then
                    local hour = tonumber(os.date("%H", static_time))
                    if (raid.hour == hour) then
                        local minute = tonumber(os.date("%M", static_time))
                        if (raid.minu == minute) then
                            if (last_execsutes[k] ~= day) then
                                last_execsutes[k] = day
                                doExecuteRaid(raid.name)
                            end
                        end
                    end
                end
            end
        end
    end
    return true
end
 
Change your function to this one, tell me what happens.

LUA:
function isInArray(array, value, caseSensitive)
	if(caseSensitive == nil or caseSensitive == false) and type(value) == "string" then
		local lowerValue = value:lower()
		for _, _value in pairs(array) do
			if type(_value) == "string" and lowerValue == _value:lower() then
				return true
			end
		end
	else
		for _, _value in pairs(array) do
			if (value == _value) then return true end
		end
	end
 
	return false
end
 
The same as in didn't work or you didn't even try it? Ipairs compares between two tables, while pairs requires a name, optionally... Pairs should work properly, at least test it if you haven't.
 
@Zuma
Since when ipairs has to do anything with to tables? Its arguments is a single table.

@topic:
Change "date" in the raid configurations to "days".
 
Back
Top