Scyrix Posted November 6, 2019 Share Posted November 6, 2019 Hello so i just watched a tutorial and tried to re-write exactly the same code as on the video it seemed to work throughout the tutorial but then at the end the error's started to pop up , BAD ARGUMENT @ 'setElementData' [Expected element at argument 1 got boolean] I have no idea what to do i tried to solve it for a long time now without effects. Spoiler function createVehicleForPlayer(player, command, model) local db = exports.db:getConnection() local x,y,z = getElementPosition(player) y = y+5 dbExec(db,"INSERT INTO vehicles(model, x, y, z) VALUES (?,?,?,?)",model, x , y , z) local vehicleObject = createVehicle(model,x, y, z) setElementData(vehicleObject, "id",vehicle.id,true) dbQuery(function(queryHandle) local results = dbPoll(queryHandle, 0) local vehicle = results[1] end, db,"SELECT id FROM vehicles ORDER BY id DESC LIMIT 1") end addCommandHandler("createvehicle",createVehicleForPlayer,false,false) function loadAllVehicles(queryHandle, player) local results = dbPoll(queryHandle, 0) for index, vehicle in pairs(results) do local vehicleObject = createVehicle(vehicle.model, vehicle.x, vehicle.y, vehicle.z) setElementData(vehicleObject,"id",vehicle.id,true) end end addEventHandler("onResourceStart",resourceRoot,function () local db = exports.db:getConnection() dbQuery(loadAllVehicles, db,"SELECT*FROM vehicles") end) addEventHandler("onResourceStop", resourceRoot,function () local db = exports.db:getConnection() local vehicles = getElementsByType("vehicle") for index, vehicle in pairs(vehicles) do local id = getElementData(vehicle, "id") local x,y,z = getElementPosition(vehicle) dbExec(db,"UPDATE vehicles SET x = ?, y = ?, z = ? WHERE id = ?",x,y,z,model) end end) Link to comment
gubi Posted November 6, 2019 Share Posted November 6, 2019 It happens in loadAllVehicles or in createVehicleForPlayer? Link to comment
Scyrix Posted November 7, 2019 Author Share Posted November 7, 2019 it happens in loadAllVehicles Link to comment
gubi Posted November 7, 2019 Share Posted November 7, 2019 Are you sure you have the car in the database? Add something like that to check whether the databse is empty or not: if #results > 0 then -- #results means how many rows are in the table, if rows are more then 0 then... -- code if the database IS NOT empty else outputDebugString("Vehicles database is EMPTY") -- outputs warning in debugmode (/debugscript 3) end Link to comment
JeViCo Posted November 8, 2019 Share Posted November 8, 2019 (edited) @Scyrix On my opinion the problem is right here: local results = dbPoll(queryHandle, 0) change result timeout from 0 to -1: local results = dbPoll(queryHandle, -1) Wiki: Use 0 for an instant response (which may return nil) Edited November 8, 2019 by JeViCo Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now