Im trying to load a cash value but when ever I do it loads it as a string and not an integer so ii get
[QUOTE]Hook 'showHud' Failed: [gamemodes\flood\gamemode\cl_hud.lua:46] attempt to compare number with string[/QUOTE]
Create table lua
[CODE] if !sql.TableExists("players_cash") then
query = "CREATE TABLE players_cash ('unique_id' varchar(255), 'cash' int)"
result = sql.Query(query)
print("new table")
end[/CODE]
and then I load the cash
[CODE]function loadcash(pl)
unique_id = sql.QueryValue("SELECT unique_id FROM players_cash WHERE unique_id = '"..steamID.."'")
Cash = sql.QueryValue("SELECT cash FROM players_cash WHERE unique_id = '"..steamID.."'")
pl:SetNWInt("Cash", Cash)
pl:ChatPrint("Profile Loaded.")
print(Cash)
end[/CODE]
and then when i try to echo it out it doesnt work...
[CODE]local Cash = LocalPlayer():GetNWInt("Cash")[/CODE]
I really dont get it. Ive tried setting the table to cash INTEGER, INT, INTEGER NOT NULL, NUMERIC but they all save it as a string. From my PHP/MySQL experience if you try to insert a string into an int it flips out. I dont see how this passes through and can save in an INT spot. Oh ive also tried int(11) like in phpMyAdmin.
use ply:SetNWString("Cash", tonumber(Cash))
Beautiful. Thank you so much. If only the Gmod LUA documentation was better.
No problem
[QUOTE=Deadman123;35083148]use ply:SetNWString("Cash", tonumber(Cash))[/QUOTE]
Why would you need to use networked vars? Other players do not need to know what the cash is.
Simply:
[i]Server-side:[/i]
[lua]
function _R.Player:SetCash(amount)
self.cash = amount;
umsg.Start("playerCash", self);
umsg.Long(amount);
umsg.End();
end;
function _R.Player:GetCash()
return self.cash or 0;
end;
[/lua]
[i]Client-side:[/i]
[lua]
usermessage.Hook("playerCash", function(msg)
local amount = msg:ReadLong();
LocalPlayer().cash = amount;
end);
function _R.Player:GetCash()
return self.cash or 0;
end;
[/lua]
[QUOTE=Chessnut;35088418]Why would you need to use networked vars? Other players do not need to know what the cash is.
Simply:
[i]Server-side:[/i]
[lua]
function _R.Player:SetCash(amount)
self.cash = amount;
umsg.Start("playerCash", self);
umsg.Long(amount);
umsg.End();
end;
function _R.Player:GetCash()
return self.cash or 0;
end;
[/lua]
[i]Client-side:[/i]
[lua]
usermessage.Hook("playerCash", function(msg)
local amount = msg:ReadLong();
LocalPlayer().cash = amount;
end);
function _R.Player:GetCash()
return self.cash or 0;
end;
[/lua][/QUOTE]
I was using them because he was.
Going off of what other gamemodes that ive looked at they seem to use Networked Vars. Just was following their lead. Plus its 1 line of code compared to 3?
[QUOTE=tissue901;35090442]Going off of what other gamemodes that ive looked at they seem to use Networked Vars. Just was following their lead. Plus its 1 line of code compared to 3?[/QUOTE]
efficiency != less lines
Sorry, you need to Log In to post a reply to this thread.