1

The error seems to be in the first line at "!self.Replace" I always get errors when trying to use ! in lua, if someone could help that'd be great.

 function ENT:Think()
    if ( !self.Replace ) && ( self:GetrHealth() <= 0 )  then

        self.Replace = true
        self.ReplaceTime = CurTime() + gMining.plugins[ "Rock Config" ].rockRespawn
        self.Pos = self:GetPos()
        if gMining.plugins[ "Rock Config" ].despawn then
            self:SetPos( self:GetPos() + Vector( 0, 0, -300 ) )
        elseif !gMining.plugins[ "Rock Config" ].despawn then
            self:SetRenderMode(RENDERMODE_TRANSADDFRAMEBLEND)
            if ( gMining.plugins[ "Rock Config" ].customColor == true ) then
                if gMining.mineralDB[ "gMining."..self.name ].enable == true then
                    self:SetColor( Color( gMining.mineralDB[ "gMining."..self.name ].color.r, gMining.mineralDB[ "gMining."..self.name ].color.g, gMining.mineralDB[ "gMining."..self.name ].color.b, gMining.plugins[ "Rock Config" ].rockTransparency ) )
                end
            else
                self:SetColor( Color( 255, 255, 255, gMining.plugins[ "Rock Config" ].rockTransparency ) )
            end

            self:Setvisible( 0 )
        end
    end;
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
DdOd
  • 11
  • 1
  • 3
    Lua's logical not operator is `not`. There is no `!` operator. – luther Mar 02 '19 at 05:10
  • In addition `~=` in Lua has the same meaning like `!=` in other languages. – csaar Mar 04 '19 at 07:27
  • @luther This is tagged as [garrys-mod]! Garry's Mod has a modifed lua syntax. Which allows to use `!boolean` instead of `~boolean` or `not boolean` – Mischa Mar 04 '19 at 09:37
  • also GMod Lua allows to start comments with `//` instead of `--` – Mischa Mar 04 '19 at 09:38
  • @Mischa: That tag was added by Egor after I made my comment. I'm leaving my comment up, because the OP says the `!` does *not* work, which means they're probably not using Garry's Mod. – luther Mar 05 '19 at 01:04
  • 1
    @luther Oh, I did not noticed that, the tag got added later. – Mischa Mar 05 '19 at 08:15

1 Answers1

3

As has been pointed out, Lua uses the keyword not for logical inversion, rather than the operator !. The code you posted looks like gLua: a Lua variant based off of Lua 5.1, and designed for Garry's Mod. Among its differences from pure Lua 5.1, it implements many C-style operators, as listed here. Attempting to run gLua in a regular Lua environment will not work, as base Lua doesn't support these operators, and certain built-in Lua functions behave differently in gLua.

EDIT: If executed within a gLua environment, the cause for issue is likely the use of entity.GetrHealth: this is not a base function, did you intend entity.GetHealth?

VortixDev
  • 965
  • 1
  • 10
  • 23