English A boolean value

6 replies
Goto Page
To the start Previous 1 Next To the start
21.08.14 03:05:02 pm
Up
RebornDuck
User
Offline Off
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:

Code:
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.
21.08.14 03:34:35 pm
Up
Alistaire
User
Offline Off
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.

Code:
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;

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

--to

table.insert( result, tostring( Key ) .. "=" .. tostring( Value ) ) --Line 56
IMG:http://i.imgur.com/5zhwOTP.png
21.08.14 04:20:02 pm
Up
RebornDuck
User
Offline Off
That bug seems to be gone now, but now I can't use any command that has a level restriction, this one:

Code:
1
if PlayerLevel(id) >= 15 then


The error is:

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


What causes this?
21.08.14 04:41:13 pm
Up
Alistaire
User
Offline Off
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.
IMG:http://i.imgur.com/5zhwOTP.png
21.08.14 06:05:00 pm
Up
RebornDuck
User
Offline Off
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:

Code:
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.
21.08.14 06:17:08 pm
Up
Alistaire
User
Offline Off
You shouldn't call a function before you declared it. Try again, and at the right line.

(sys/lua/RDAdministrationScript.lua:105)
IMG:http://i.imgur.com/5zhwOTP.png
21.08.14 09:11:39 pm
Up
RebornDuck
User
Offline Off
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:

Code:
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