Forum

> > CS2D > Scripts > Concatenate a boolean value, Lua Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Concatenate a boolean value, Lua Error

8 replies
To the start Previous 1 Next To the start

old Concatenate a boolean value, Lua Error

Cebra
User Off Offline

Quote
1
2
3
4
LUA ERROR: sys/lua/autorun/playermenu.lua:10: attempt to
concatenate a boolean value-> sys/lua/autorun
/playermenu.lua:10: in function <sys/lua/autorun
/playermenu.lua:2>-> in Lua hook 'serveraction', params: 1, 1

i get this error message sometimes, when i try my script
then, a few moments later, it works again.
What i can do?

Atomic

old Re: Concatenate a boolean value, Lua Error

Cebra
User Off Offline

Quote
thats is the complete script
Spoiler >

old Re: Concatenate a boolean value, Lua Error

EngiN33R
Moderator Off Offline

Quote
1
for i=1,#(player(0,"table")) do
This piece of code iterates over all existing players, sure, but it only gets the indices of the player table - the indices aren't always equal to their values when it comes to player IDs. A better way would be to write the code like this:

More >


Though to be fair, the script has a couple of weak points and could do with a rewrite.

old Re: Concatenate a boolean value, Lua Error

Cebra
User Off Offline

Quote
thank you all,
@user VADemon: i learn at the moment lua and i wrote this to train, but thank you for the link, i will look for it later,

@user EngiN33R: yes there are mistakes in but the most i write in a few min and the help of bowlinghead

'k' var is like the 'i' in my script and the 'v' have the value of the actual table content, right?
edited 1×, last 17.01.16 04:13:15 pm

old Re: Concatenate a boolean value, Lua Error

Rainoth
Moderator Off Offline

Quote
k is the index in table, v is the value marked with that index in table
for example, index 5 means it's 5th in the table,
for example, value "potato" means that there's "potato" in 5th spot in the table.
the way you loop i is very different, you're getting numbers from 1 to whatever length is, so you may not even get proper numbers.
for example:
playertable = {10, 5, 3, 4}
the values of players (this is very simplified because players actually have tables of values and not just random numbers) are like I wrote above, like lets say it's how much health they have (one has 10, the other has 5, then 3 and finally the last player has 4)
All the players joined one after another so they're index like so:
[1] = 10,
[2] = 5,
[3] = 3,
[4] = 4
when you loop with i, you get the length. The script gets the length (4) because there's 4 players and loops: 1,2,3,4. Great!
Player 3 leaves...
Now everything looks like this.
[1] = 10,
[2] = 5,
[4] = 4
You loop i again and get the length (3) because there's 3 players. Now you loop: 1,2,3 ??? 3 does not exist (because he left earlier) and 4 wasn't even looped (because table length does not reach the highest id).
*Sad trombone*

Which is why you should use pairs, it returns index and value of table correctly, even if the player (who say is #3) left.
If you check if player(i,"exists"), sure it'll prevent trying to do crap for nonexistent players, but it still won't loop all players and thus may not do what you aim to do in your code.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview