Forum

> > CS2D > Scripts > A boolean value
Forums overviewCS2D overview Scripts overviewLog in to reply

English A boolean value

6 replies
To the start Previous 1 Next To the start

old A boolean value

RebornDuck
User Off Offline

Quote
Hey, I'm currently working on a script and I've gotten an error I can't solve (btw, I'm currently learning lua so please skip the "lol this is so easy" comments, ty). It would be great if someone could help me.

The error:

1
LUA ERROR: sys/lua/serverfiles/table.lua:56: attempt to concatenate local 'Value' (a boolean value)

It gets affected whenever I use the mute and speclock command. The mute and speclock doesn't get removed after the specified time, it stays forever.

Line 56 from table.lua:

Spoiler >


Mute and speclock commands + when they are supossed to end (not on same lua):

Spoiler >


If anyone has any ideas on what to do, please tell me.

Thanks.

old Re: A boolean value

Alistaire
User Off Offline

Quote
One of your tables keys holds a boolean - specifically User[id]["muted"] and User[id]["speclock"] for each id. Lua won't concatenate booleans (won't turn true or false into strings), and returns an error.

Another error is that your table won't print keys that hold a false, because the and operator checks whether Value exists and is not false.

To fix this, store booleans as a 1 and 0, and not as a boolean true and false.

1
2
3
4
5
6
7
8
9
10
11
User[id]["muted"] = true
User[id]["speclock"] = true
User[id]["muted"] = false
User[id]["speclock"] = false

--to

User[id]["muted"] = 1
User[id]["speclock"] = 1
User[id]["muted"] = 0
User[id]["speclock"] = 0

----

Alternatively you could do the following;

1
2
3
4
5
table.insert( result, Key .. "=" .. Value ) --Line 56

--to

table.insert( result, tostring( Key ) .. "=" .. tostring( Value ) ) --Line 56

old Re: A boolean value

RebornDuck
User Off Offline

Quote
That bug seems to be gone now, but now I can't use any command that has a level restriction, this one:

1
if PlayerLevel(id) >= 15 then

The error is:

1
LUA ERROR: sys/lua/RDAdministrationScript.lua:105: attempt to compare number with string

What causes this?

old Re: A boolean value

Alistaire
User Off Offline

Quote
Check if the script makes sense, whether it should always return a number. If it doesn't always return a number, change return * to return tonumber( * ) to make sure it's always a number.

As you should always do with these kinds of errors, try to print( tostring( PlayerLevel( id ) ) ) to see if it's actually a number. Also try to find out whether PlayerLevel( id ) is ever not a number, with print( tonumber( PlayerLevel( id ) ) and "Number" or "Not a number" ). Basic bugfixing.

old Re: A boolean value

RebornDuck
User Off Offline

Quote
I tried checking with both print( tostring( PlayerLevel( id ) ) ) and print( tonumber( PlayerLevel( id ) ) and "Number" or "Not a number" ). All I get is this error:

1
LUA ERROR: sys/lua/RDAdministrationScript.lua:1: attempt to call global 'PlayerLevel' (a nil value)

I tried adding PlayerLevel = {} and PlayerLevel(id) = {} to the script but it didn't help.

old Re: A boolean value

Alistaire
User Off Offline

Quote
You shouldn't call a function before you declared it. Try again, and at the right line.

(sys/lua/RDAdministrationScript.lua:105)

old Re: A boolean value

RebornDuck
User Off Offline

Quote
Oh, I thought that it didn't matter. Well, I got the same old error in the console, so I added return tonumber in the PlayerLevel(id) function and the commands now work, but the tag is always activated for some reason, don't know why.

I also got a new error:

1
LUA ERROR: sys/lua/RDAdministrationScript.lua:8: attempt to index field '?' (a nil value)

Line:

Spoiler >


I tried adding UserData["TRANKTIME"] = 0 and UserData["TRANK"] = 0 but it didn't fix it.

What kind of sorcery is this? I fix a bug, two more are created.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview