DdOd
DdOd

Reputation: 11

Lua ! not expected

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;

Upvotes: 1

Views: 1040

Answers (1)

VortixDev
VortixDev

Reputation: 1013

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?

Upvotes: 3

Related Questions