A
A
AndRussia2020-10-09 15:15:09
Lua
AndRussia, 2020-10-09 15:15:09

MTA (Multi Theft Auto) LUA - Why does it return 0 or false?

Hello. The problem is:
There is a code

function playerRegister(login, password)
  local player = source
  local mynick getPlayerName(source)
  local mylogin = getAccount(login)
  local mypassword = getAccount(password)
  if not getAccount(login) then
    addAccount(login, password)
    dbQuery(db, "INSERT INTO users(login, nickname, password, status, hp, money, level) VALUES(" .. tostring( mylogin ) .. ", " .. tostring( mynick ) .. ", " .. tostring( mypassword ) .. ", 1, 100, 1500, 16)")
    outputChatBox('Аккаунт успешно создан.', player)
  else
    outputChatBox('Аккаунт с таким логином существует!', player)
  end
end
addEvent('playerRegister', true)
addEventHandler('playerRegister', root, playerRegister)

And in dbQuery login and password values ​​get 0 or false in mysql
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2020-10-09
@dollar

The problem could be anything .
There is no need to guess and puzzle. Get into debugging .

At least like this:
function playerRegister(login, password)
  outputChatBox('Enter playerRegister...')
  outputChatBox('login=',login,' password=',password)
  local player = source
  outputChatBox('player=',player)
  local mynick getPlayerName(source)
  outputChatBox('mynick=',mynick)
  local mylogin = getAccount(login)
  outputChatBox('mylogin=',mylogin)
  local mypassword = getAccount(password)
  outputChatBox('mypassword=',mypassword)
  if not getAccount(login) then
    outputChatBox('Creatre new account (' .. tostring(login) .. ')...')
    addAccount(login, password)
    outputChatBox('dbQuery:')
    local query = "INSERT INTO users(login, nickname, password, status, hp, money, level) VALUES("
      .. tostring( mylogin ) .. ", " .. tostring( mynick ) .. ", " .. tostring( mypassword ) .. ", 1, 100, 1500, 16)"
    outputChatBox(query)
    dbQuery(db, query)
    outputChatBox('Аккаунт успешно создан.', player)
  else
    outputChatBox('Аккаунт с таким логином существует!', player)
  end
end
addEvent('playerRegister', true)
addEventHandler('playerRegister', root, playerRegister)

The chance of guessing is not 100%. But with the help of debugging in the programming world, you are guaranteed to get to the bottom of the cause.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question