• Working on a stamina system but getting an "attempt to compare number with bool"
    11 replies, posted
As you can see from the title, I am working on a stamina system but I'm having an issue with checking the NWInt as it shows an error: sv_main.lua:52: attempt to compare number with boolean Here is the code: -- Stamina system local staminaMax = 20 local defaultJumpPower = 200 local staminaNonCrouchDelay = 2 local staminaCrouchDelay = 1 local staminaTakeAwayDelay = 2 local function StaminaTakeAway(ply)     if CurTime() < staminaTakeAwayDelay then return end     if not ply:GetNWInt("staminasystem") <= 0 then         ply:SetNWInt("staminasystem", ply:GetNWInt("staminasystem") - 1)     end end local function StaminaRestore(ply)     if ply:Crouching() then         if CurTime() < staminaCrouchDelay then return end         if not ply:GetNWInt("staminasystem") >= staminaMax then             ply:SetNWInt("staminasystem", ply:GetNWInt("staminasystem") + 1)         end     else         if CurTime() < staminaNonCrouchDelay then return end         if not ply:GetNWInt("staminasystem") >= staminaMax then             ply:SetNWInt("staminasystem", ply:GetNWInt("staminasystem") + 1)         end     end end local function SetStamina(ply)     ply:SetNWInt("staminasystem", staminaMax)     ply:SetJumpPower(200) end hook.Add("KeyPress", "OnKeyPress", function(ply, key)     if key == IN_SPEED then         StaminaTakeAway(ply)     end end) hook.Add("KeyRelease", "OnKeyRelease", function(ply, key)     if key == IN_SPEED then         StaminaRestore(ply)     end end) hook.Add("PlayerSpawn", "OnPlayerSpawn", function(ply)     SetStamina(ply)     net.Start("staminasystem")     net.Send(ply) end)
What is on line 52?
You have to give it a number, not IN_SPEED IN Enumerations Look at the list. Each KEYWORD has a decimal number. The number is what you have to put in the if statement. Not IN_SPEED
https://i.imgur.com/wZSn83C.png https://i.imgur.com/ZHcNbcZ.png Do you even know what enumerations are?
Dude... an enumeration is just a global static variable that describes that number... It's literally a variable. Please use enums as enums are self documenting, and decimal numbers might change across Gmod versions (the Wiki states so)
I think he is drunk today. We all supposed him to know that.
if not ply:GetNWInt("staminasystem") >= staminaMax then
if not x > y then big brain shit right there The problem is the "not". It's converting "x" to a bool. Remove it and use the proper comparison operators.
You can: if ply:GetNWInt("staminasystem") >= staminaMax then or if not (ply:GetNWInt("staminasystem") >= staminaMax) then or if ply:GetNWInt("staminasystem") < staminaMax then
do not do this for the love of all things holy
Okay, thank you guys for helping.
CurTime is constantly going up as the server is up, your comparisons are always gonna fail after the server is up for a few seconds. You have to set a variable to it's current value to compare it to. Also make sure that variable is local to the player somehow, and now globally shared between all players.
Sorry, you need to Log In to post a reply to this thread.