Forum

> > CS2D > Scripts > Bot Script Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Bot Script Error

2 replies
To the start Previous 1 Next To the start

old Bot Script Error

G3tWr3ck3d
User Off Offline

Quote
Hello, I have a problem with a bot script. It says :
× LUA ERROR: sys/lua/server.lua:21: attempt to compare number with table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mbots = 4
bots = {}

for i=1,mbots do
     parse("bot_add")
     table.insert(bots,player(0,"table")[#player(0,"table")])
end

function countplayers()
     local c=0
     for _,i in pairs(player(0,"table")) do
          if not player(i,"bot") then
               c=c+1
          end
     end
     return c
end

addhook("join","checkbots")
function checkbots()
     if bots>0 then
          parse("kick "..bots[#bots])
     end
end

addhook("leave","checkbots2")
function checkbots2()
     local ply=countplayers()
     if ply<mbots then
          parse("bot_add")
     end
end

So if is here anyone that can help me fix it I would be grateful.
edited 2×, last 10.03.14 09:36:54 am

old Re: Bot Script Error

DC
Admin Off Offline

Quote
Try to use your brain
Quote
LUA ERROR: sys/lua/server.lua:21: attempt to compare number with table

This means that in line 21 you are trying to compare a number with a variable which is a table. This doesn't work because you can't compare two different types with >.

Line 21 is:
1
if bots>0 then

The variable is bots
The number is 0
The comparison is >

You have to use something else instead of bots. Maybe #bots to get the number of elements in the table bots.

old Re: Bot Script Error

G3tWr3ck3d
User Off Offline

Quote
Oh, now I see the problem. You've got an eagle eye DC. Thanks, you can close the thread now.

EDIT: I've encountered a problem, if I make a Public server the bot gets kicked and if I join with another cs2d client I get kicked and a bot is added. I have also tried with dedicated and it doesn't kick the bot, the bot just freezes and doesn't move when I join the server, no kick at all.

√ EDIT: Nvm, Engy fixed the script.
edited 5×, last 10.03.14 03:34:04 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview