Jump to content

[HELP] Please help, Issue with Lua and Boolean


Recommended Posts

Posted

Hello! Thank you for taking your time to look at this. I have a Roleplay server, And everything is goin well, Exept the login. In the console when i hit Login, I get this: attempt to compare number with boolean

Here is where it says the error is:

local accountCheckQuery = mysql:query(accountCheckQueryStr)

if mysql:num_rows(accountCheckQuery)>0 then

accountData = mysql:fetch_assoc(accountCheckQuery)

mysql:free_result(accountCheckQuery)

Please help, Thanks in advanced!

image1_zps9f6c3af9.png

  • Moderators
Posted
local accountCheckQuery = mysql:query(accountCheckQueryStr)  
-- get database account 

Script problem:

mysql:num_rows(accountCheckQuery)  
-- returns boolean =  false/true at the moment 

if mysql:num_rows(accountCheckQuery)>0 then  
-- here you are comparing the boolean with the number 0. 

and how the solve it?

I have no idea, because this is the result from something that went wrong at another part of the script.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
  
if mysql:num_rows(accountCheckQuery)>0 then 

is bad

use

if accountCheckQuery:num_rows() > 0 then 

all:

  
local accountCheckQuery = mysql:query(accountCheckQueryStr) 
if accountCheckQuery:num_rows() > 0 then 
accountData = mysql_fetch_assoc(accountCheckQuery) 
accountCheckQuery:free_result() 
  

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...