• Error is causing a boolean...
    9 replies, posted
Hi. I've been developing some pointshop // Custom Menu code and I've hit a wall. I'm receiving this error [ERROR] gamemodes/prop_hunt/gamemode/init.lua:80: attempt to call global 'PointsForKill' (a boolean value) for each line that I use a custom fuction, for example... function FirstBlood(attacker,victim) if GetConVar("PH_FIRSTBLOOD"):GetInt() < 1 and !GAMEMODE:InRound() then return end if !FirstBlooded then local firstBloodPoints = GetConVar( "PH_POINTSHOP_FIRSTBLOOD_POINTS"):GetInt() FirstBlooded = true BroadcastMsg( Color(255,30,0), attacker:Nick().." got First Blood!" ) BroadcastSound("firstblood.mp3") hook.Run("ST_FirstBlood",attacker,victim) if PointsForKill() then attacker:PS_GivePoints(firstBloodPoints) attacker:PS_Notify("First Blood for " .. tostring(firstBloodPoints) .. " extra " .. PS.Config.PointsName .. "!") end end Everything else runs fine, however, when a player kills another, tries to taunt randomly or using our menu, it creates the error per each GivePoints. e.g. if (ply.last_point_time <= CurTime()) and (ply:Team() == TEAM_PROPS) and PointsForTaunt() then ply:PS_GivePoints(PointsForTauntAmount) then ply:PS_Notify("You got " .. PointsForTauntAmount .. " " .. PS.Config.PointsName .. " for taunting!") end Above is the code which tells the server to award points to a player for taunting randomly, i.e. it will read the length of the taunt, and award points based on its length. I receive the error when a player taunts. [ERROR] gamemodes/prop_hunt/gamemode/init.lua:526: attempt to call global'PointsForTaunt' (a boolean value) I'm aware it needs a numeric value however I have no idea how to fix the error and make the damn thing work. Any advice would be great, thanks.
Luckily this is one of the cases where the error logging is fairly helpful. PointsForTaunt and PointsForKill are boolean variables, that means they are values that can store true or false. You are putting ( )'s at the end, which is the syntax for a function call. It is therefore trying to call them as functions, and failing because they're not functions at all, they're just boolean variables. If you remove the parentheses at the end of each of those variables the code should work as you expect it to, as its just directly checking the value of the variables for true or false in the condition of the if statement. See FirstBlooded to see an example of where a boolean is checked directly. !GAMEMODE:InRound() has parentheses at the end because it is a function that ultimately returns a boolean value. Let me know if I can clarify anything.
I'll give it a shot, thanks mate, i'll let you know if it works/doesn't work
Okay so... these are functions after all apparently, at least at some point If you're defining a function you DO want the parentheses at the end... i.e. function PointsForKill() should have parentheses. If you call it as a function you also want parentheses. So your original code was probably fine, but those function names are defined as boolean variables, at some point before you attempt to call them. This seems beyond basic syntax issues, so not sure how much I'll be able to help without seeing all your code and spending a while understanding it.
I see, I'll have a detailed look through the code and see if I'm missing any parentheses anywhere. Thanks anyway, not many people take the time out to help
-- Edit -- Right, I've had a look and just can't see the problem, parentheses are all fine... The exact line of code that's causing an issue is... local PointsForTauntAmount = math.Round(rand_taunt[3] / 2) Apparently that's causing a boolean value. Heres the extract local PointsForTauntAmount = math.Round(rand_taunt[3] / 2) if (ply.last_point_time <= CurTime()) and (ply:Team() == TEAM_PROPS) and PointsForTaunt() then ply:PS_GivePoints(PointsForTauntAmount) ply:PS_Notify("You got " .. PointsForTauntAmount .. " " .. PS.Config.PointsName .. " for taunting!") end again, I can't see why it's causing a boolean value error. (Specifically the top line of code, PointsForTauntAmount) is causing the error. The code looks fine to me, all taunts play just fine, however it refuses to give points and doesn't give points over time either. Any help would be appreciated, been 4 days now and can't crack it >.<
You are making this very confusing, what exactly are you calling here? rand_taunt[3]
I finally, fixed it myself. Here's how (for anyone else who has this issue..) function PointsForKill() if DEBUG or !GAMEMODE:InRound() then return false end if GetConVar("PH_POINTSHOP_POINTS_KILL"):GetInt() > 0 then return PS and true end end is fine, please the parentheses as they are PointsForKill() and that will create your function, when it needs to be called upon, REMOVE the parentheses. So, it goes FROM if (ply.last_point_time <= CurTime()) and (ply:Team() == TEAM_PROPS) and PointsForTaunt() then ply:PS_GivePoints(PointsForTauntAmount) ply:PS_Notify("You got " .. PointsForTauntAmount .. " " .. PS.Config.PointsName .. " for taunting!") end to if (ply.last_point_time <= CurTime()) and (ply:Team() == TEAM_PROPS) and PointsForTaunt then ply:PS_GivePoints(PointsForTauntAmount) ply:PS_Notify("You got " .. PointsForTauntAmount .. " " .. PS.Config.PointsName .. " for taunting!") end You don't need the () at the end of the PointsForTaunt for anywhere else it's called. I hope this helps anyone else who has an issue with booleans and functions. Peaceout.
Why return a static value of “true”? Also using the function name without the parentheses (not calling it) will simply be true if the function exists and false/nil otherwise. This will most likely always be true depending on if your function is defined before that if statement is ran.
the problem is you ONLY return any value if a certain OTHER value is true. what happens if that value is false? it won't default to returning false. the last line of function PointsForKill() should be some sort of return statement, either true or false, so that if the condition isn't met, something is still returned.
Sorry, you need to Log In to post a reply to this thread.