Jump to content

"Error: Attempt to compare number with boolean"


Recommended Posts

Hello there!

I can't seem to find the problem here. This line...

if(getElementData(source, "wwacc.timesSpawned") > 0 and getElementData(source, "wwacc.needsSelect") == false) then

... gives me this error:

Error: attempt to compare number with boolean

It's not a boolean, at least it's not supposed to be. Is there any way to set the data type, like float, int, bool? Does anyone see the problem in that line of code?

Help would be greatly appreciated, thanks.

Link to comment

you had to set it to boolean somewhere

maybe you are doing something like

some_value_that_you_expect_to_be_integer = someFunctionReturningIntegerOrFalseOnFailure(some_argument_causing_function_to_return_false)
-- then
setElementData(source, "wwacc.timesSpawned", some_value_that_you_expect_to_be_integer)

try to output value every time you read and set it (it's called debug ;p)

Link to comment
This is weird.

I use this every time they spawn:

local timesSpawned = getElementData(source, "wwacc.timesSpawned") + 1
setElementData(source, "wwacc.timesSpawned", timesSpawned)

But still, when I output it with my test command, it always outputs "false".

on first spawn your wwacc.timesSpawned = nil

you want to add 1 to nil, probably it result with false.

then you are adding 1 to false, and it keeps beeing false.

Link to comment
if getElementData(source, "wwacc.timesSpawned") == nil or getElementData(source, "wwacc.timesSpawned") == false then
setElementData(source, "wwacc.timesSpawned", 0)
end
local timesSpawned =  getElementData(source, "wwacc.timesSpawned") + 1
setElementData(source, "wwacc.timesSpawned", timesSpawned)

Here ya go ;)

Link to comment

Yea, it works. Thanks.

Though when I restart the server same error appears when trying to spawn. Also, this code...

spawnPlayer(source, getAccountData(account2, "wwacc.xPos"), getAccountData(account2, "wwacc.yPos"), getAccountData(account2, "wwacc.zPos"), 0.0, getAccountData(account2, "wwacc.skin"), getAccountData(account2, "wwacc.interior"), 0, getAccountData(account2, "wwacc.team"))

... gives me the "Bad player pointer" error. What's wrong?

Link to comment

Triggered when a player logs in.

function onLog(account)
local account2 = getAccount(account)
setPlayerName(source, account)
if(getAccountData(account2, "wwacc.needsSelect") == true) then
triggerClientEvent("showGUI_teamSelect", source)
end
 
if(getAccountData(account2, "wwacc.timesSpawned") == nil) then
setAccountData(account2, "wwacc.timesSpawned", 0)
end
 
if(getAccountData(account2, "wwacc.timesSpawned") > 0) then
if(getAccountData(account2, "wwacc.needsSelect") == false) then
spawnPlayer(source, getAccountData(account2, "wwacc.xPos"), getAccountData(account2, "wwacc.yPos"), getAccountData(account2, "wwacc.zPos"), 0.0, getAccountData(account2, "wwacc.skin"), getAccountData(account2, "wwacc.interior"), 0, getAccountData(account2, "wwacc.team"))
fadeCamera(source, true)
setCameraTarget(source, source)
end
end
 
if(getAccountData(account2, "wwacc.timesSpawned") == 0 and getAccountData(account2, "wwacc.needsSelect") == false) then
if(getAccountData(account2, "wwacc.team") == 1) then
setAccountData(account2, "wwacc.xPos", 245.9324)
setAccountData(account2, "wwacc.yPos", 1990.0793)
setAccountData(account2, "wwacc.zPos", 17.6406)
spawnPlayer(source, 245.9324, 1990.0793, 17.6406)
		setPlayerInterior(source, 0)
givePlayerMoney(source, 0)
		setPlayerHealth(source, 100)
		setPlayerArmour(source, 0)
setPlayerTeam(source, 1)
fadeCamera(source, true)
setCameraTarget(source, source)
end
 
if(getAccountData(account2, "wwacc.team") == 2) then
setAccountData(account2, "wwacc.xPos", -2681.7974)
setAccountData(account2, "wwacc.yPos", 2151.6648)
setAccountData(account2, "wwacc.zPos", 55.8125)
spawnPlayer(source, -2681.7974, 2151.6648, 55.8125)
		setPlayerInterior(source, 0)
givePlayerMoney(source, 0)
		setPlayerHealth(source, 100)
		setPlayerArmour(source, 0)
setPlayerTeam(source, 2)
fadeCamera(source, true)
setCameraTarget(source, source)
end
end
end

Link to comment

May I ask you what do you need getAccount for? onPlayerLogin passes 3 arguments to handlers, 1st being player's previous account and 2nd the account player logged into, 3rd a boolean value indicating if player was auto logged in. So, what's the point of getAccount? Also, why do you pass account element to getAccount function if it expects username and/or password (strings) not account? You should read wiki more carefully. Just answer these questions.

I'm honestly surprised that source is not the player who logged in. What is it then? Debug the function.

Link to comment

I hope I understood the code correctly, but I think the problem is that the part, where you initialize the element data is at spawn, but you already work with it at login, which is before spawn.

Therefore you should add the following snippet:

addEventHandler("onPlayerJoin", getRootElement(),
function ()
setElementData(source, "wwacc.timesSpawned", 0)
end
)

This will initialize the element data at join and should solve your problem.

Link to comment

I've fixed the spawning thing. What I did is forward getLocalPlayer value to the server login event and then use it to call the other function... It works actually :o.

but you already work with it at login, which is before spawn.

Yes, I do. But I only check if the player spawned already before their current visit.

I'm fiddling with the element data now. It always says "attempt to compare number with boolean", again... It works fine when I first register and login. I can also disconnect and reconnect back, but when I restart the server, it resets.

What should I do? Should I use set/getElementData and then save it with set/getAccountData then reset it back by reading from the file?

Link to comment
I've fixed the spawning thing. What I did is forward getLocalPlayer value to the server login event and then use it to call the other function... It works actually :o.

but you already work with it at login, which is before spawn.

Yes, I do. But I only check if the player spawned already before their current visit.

I'm fiddling with the element data now. It always says "attempt to compare number with boolean", again... It works fine when I first register and login. I can also disconnect and reconnect back, but when I restart the server, it resets.

What should I do? Should I use set/getElementData and then save it with set/getAccountData then reset it back by reading from the file?

I have no idea what you're talking about myself. Show us your current code and try to ask the questions again...

Link to comment
I have no idea what you're talking about myself. Show us your current code and try to ask the questions again...

It's kinda hard to explain.

So, let's say I register. If I disconnect and reconnect to my server and login, everything will work perfectly fine. But, if I restart the server itself, then it seems that timesSpawned in the accounts file resets for some reason.

This is the handler that registers the player or logins them if they're already registered:

function onRegister(playerid, user, pass)
local account = getAccount(user, pass)
if(account ~= false) then
if(logIn(playerid, account, pass) == true) then
triggerClientEvent("hideLoginWindow", playerid)
		onLog(playerid, account, pass)
outputChatBox("You have been successfully logged in.", playerid)
else
outputChatBox("Error: Invalid password, username or already logged in.", playerid)
end
else
	account = addAccount(user, pass)
setAccountData(account, "wwacc.xPos", x)
setAccountData(account, "wwacc.yPos", y)
setAccountData(account, "wwacc.zPos", z)
setAccountData(account, "wwacc.interior", int)
setAccountData(account, "wwacc.team", 0)
 
setAccountData(account, "wwacc.needsSelect", true)
setAccountData(account, "wwacc.timesSpawned", 0)
setAccountData(account, "wwacc.waitingMoney", 0)
setAccountData(account, "wwacc.money", 0)
setAccountData(account, "wwacc.adminLevel", 0)
setAccountData(account, "wwacc.muted", false)
setAccountData(account, "wwacc.regimentLeader", 0)
setAccountData(account, "wwacc.regimentMember", 0)
setAccountData(account, "wwacc.hasRadio", false)
setAccountData(account, "wwacc.radioFreq", 0)
 
if(logIn(playerid, account, pass) == true) then
local x, y, z = unpack(WandererSpawns[math.random(1, 13)])
setPlayerName(playerid, user)
triggerClientEvent("hideLoginWindow", playerid)
triggerClientEvent("showGUI_teamSelect", playerid)
outputChatBox("You have been successfully registered and logged in.", playerid)
else
outputChatBox("Error: Invalid password, username or already logged in.", playerid)
end
end
end

Here's the handler that logins the player:

function onLogin(playerid, user, pass)
local account = getAccount(user, pass)
if(account ~= false) then
if(logIn(playerid, account, pass) == true) then
triggerClientEvent("hideLoginWindow", playerid)
		onLog(playerid, account, pass)
outputChatBox("You have been successfully logged in.", playerid)
else
outputChatBox("Error: Invalid password, username or already logged in.", playerid)
end
else
outputChatBox("Error: Invalid username or password.", playerid)
end
end

And here's the onLog function which you can spot in my code a lot of times:

function onLog(playerid, account, pass)	
setPlayerName(playerid, getAccountName(account))
if(getAccountData(account, "wwacc.needsSelect") == true) then
triggerClientEvent("showGUI_teamSelect", playerid)
end
 
if(getAccountData(account, "wwacc.timesSpawned") == nil or getAccountData(account, "wwacc.timesSpawned") == false) then
setAccountData(account, "wwacc.timesSpawned", 0)
end
 
if(getAccountData(account, "wwacc.timesSpawned") > 0) then
if(getAccountData(account, "wwacc.needsSelect") == false) then
fadeCamera(playerid, true)
spawnPlayer(playerid, getAccountData(account, "wwacc.xPos"), getAccountData(account, "wwacc.yPos"), getAccountData(account, "wwacc.zPos"), 0.0, getAccountData(account, "wwacc.skin"), getAccountData(account, "wwacc.interior"), 0, getAccountData(account, "wwacc.team"))
setCameraTarget(playerid, playerid)
end
end
 
if(getAccountData(account, "wwacc.timesSpawned") == 0 and getAccountData(account, "wwacc.needsSelect") == false) then
if(getAccountData(account, "wwacc.team") == 1) then
setAccountData(account, "wwacc.xPos", 245.9324)
setAccountData(account, "wwacc.yPos", 1990.0793)
setAccountData(account, "wwacc.zPos", 17.6406)
fadeCamera(playerid, true)
spawnPlayer(playerid, 245.9324, 1990.0793, 17.6406)
setCameraTarget(playerid, playerid)
setElementInterior(playerid, 0)
setElementHealth(playerid, 100)
		setPedArmour(playerid, 0)
end
 
if(getAccountData(account, "wwacc.team") == 2) then
setAccountData(account, "wwacc.xPos", -2681.7974)
setAccountData(account, "wwacc.yPos", 2151.6648)
setAccountData(account, "wwacc.zPos", 55.8125)
fadeCamera(playerid, true)
spawnPlayer(playerid, -2681.7974, 2151.6648, 55.8125)
setCameraTarget(playerid, playerid)
setElementInterior(playerid, 0)
setElementHealth(playerid, 100)
		setPedArmour(playerid, 0)
end
end
end

Link to comment

I get no message if I register, disconnect and connect back on. But if I restart the server, it comes from this line:

if(logIn(playerid, account, pass) == true) then

As I said, it works until I restart the server.

EDIT: There are no more errors when I log in after restarting the server, but it still doesn't spawn me.

EDIT2: I've just noticed that there are two timesSpawned saves in the accounts file. I guess one of them is still the old boolean, while the other is a numeric one. They both reset though and give me no errors.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...