Facepunch / garrysmod-issues

Garry's Mod issue tracker
145 stars 56 forks source link

TOOLs don't have an IsValid() method, causing IsValid(Tool) to always return false #5283

Closed Andrew-Eathan closed 2 years ago

Andrew-Eathan commented 2 years ago

Details

Tools don't have an IsValid() method, and judging by the code for the global IsValid(), it's permanently returning false because of that

Steps to reproduce

function TOOL:Think()
    print(self.IsValid, IsValid(self)) -- prints "nil false"
end
robotboy655 commented 2 years ago

Should it? At what point can you get an invalid tool object?

Andrew-Eathan commented 2 years ago

Should it? At what point can you get an invalid tool object?

It doesn't really matter whether or not you can get an invalid tool object, the issue is in the title: IsValid(Tool) always returns false, which is flawed

Kefta commented 2 years ago

https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/util.lua#L229

This condition could be changed to true but who knows what that would break. Just don't send tools into IsValid: know what types you are dealing with instead of blindly sending data in.

robotboy655 commented 2 years ago

How is it flawed? You are not meant to use IsValid on every single variable, only in those scenarios where an object might be invalid, hence the name of the function.

IsValid it will return false for more than just tools.