Jump to content

Recommended Posts

Posted

 I have two components, each in a different door, but when I open any door the light comes on, would you expect it to work only with the ones I have connected in flowgraph editor?



image.thumb.png.722c305dc398b5add1cc4a46c4c498fa.png

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

I can't understand, I only have two connected between the editor, but it happens that the others are not connected, but still the signal is triggered and the light comes on.

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

Unfortunately I have nothing to debug so I cannot tell you the answer.

Maybe you have some global variable declared that is being shared by all instances of the component.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

 

I have simplified the code, I am going to put the rest and show it later, so it works very well.

image.thumb.png.20558c7fb13f74c033c1a303dadf620d.png

 

KaraConsole = {}
KaraConsole.name = "KaraConsole"
KaraConsole._inside = false
function KaraConsole:Load()
 
end
 
function KaraConsole:Collide(ent, pos, normal, speed)
    if ent.name == "controller" then
        self._inside = true
       
    end
end
 
function KaraConsole:Update()
 
    if  self._inside == true then
        self:FireOutputs("doorOpened")
    end
 
end


 
RegisterComponent("KaraConsole", KaraConsole)
return KaraConsole

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

@Josh

Something is definitely wrong with my code. 

Without being connected the light comes on.  Shall I send you the project?



image.thumb.png.594b3ef3bb88e29e16ff9f5bc09df9f3.png

 

 

KaraConsole = {}
KaraConsole.name = "KaraConsole"
 
local ICON_OWNER = nil
local doorTypes = { "Simple", "Double", "Hangar" }
 
local s = ""
 
function KaraConsole:Load()
 
 
    self.doorTypeIndex = self.doorType or 0 -- Recibe el índice del JSON
    self.doorType = doorTypes[self.doorTypeIndex + 1] or "Simple"
 
    self.linkedDoorA = self.linkedDoorA
    self.linkedDoorB = self.linkedDoorB
    self.requireInput = (self.requireInput ~= false)
    self.openSpeed = self.openSpeed or 0.01
    self._doorTravelDistance = self._doorTravelDistance or 1.9 -- Distancia para Simple y Double
    self._doorTravelDistanceHangar = self._doorTravelDistanceHangar or 2.5 -- Distancia para Hangar
 
    self._inside = false
    self._wasInside = false
    self.state = "closed"
    self.closeStartTime = nil
end
 
function KaraConsole:Start()
    self._doorA = self.linkedDoorA
    self._doorB = self.linkedDoorB
 
    if self._doorA then
        self._doorAOrigPos = self._doorA:GetPosition()
 
        if self.doorType == "Simple" or self.doorType == "Double" then
            local offsetA = Vec3(self._doorTravelDistance, 0, 0)
            self._doorATargetPos = TransformPoint(offsetA, self._doorA, nil)
        elseif self.doorType == "Hangar" then
            self._doorATargetPos = Vec3(
                self._doorAOrigPos.x,
                self._doorAOrigPos.y + self._doorTravelDistanceHangar,
                self._doorAOrigPos.z
            )
        end
    end
 
    if self.doorType == "Double" and self._doorB then
        self._doorBOrigPos = self._doorB:GetPosition()
        local offsetB = Vec3(-self._doorTravelDistance, 0, 0)
        self._doorBTargetPos = TransformPoint(offsetB, self._doorB, nil)
    end
end
 
function KaraConsole:Collide(ent, pos, normal, speed)
    if ent.name == "controller" then
        self._inside = true
        self.closeStartTime = nil
    end
end
 
function KaraConsole:Update()
    if not _G.uiLevel01 then return end
 
    local inside = self._inside
    local wantIcon = inside and self.requireInput and (self._doorA or self._doorB)
 
    if wantIcon and ICON_OWNER ~= self then
        _G.uiLevel01:ShowEIcon(); ICON_OWNER = self
    elseif ICON_OWNER == self and not wantIcon then
        _G.uiLevel01:HideEIcon(); ICON_OWNER = nil
    end
 
    if wantIcon and ActiveWindow():KeyHit(KEY_E) then
        self.state = (self.state == "open" or self.state == "opening") and "closing" or "opening"
        self.closeStartTime = nil
        _G.uiLevel01:HideEIcon(); ICON_OWNER = nil
    end
 
    if inside and not self.requireInput and self.state == "closed" then
        self.state = "opening"
    end
 
    if self.state == "opening" then
        s = self.state
        if self._doorA then self:_moveDoor(self._doorA, self._doorATargetPos) end
        if self.doorType == "Double" and self._doorB then self:_moveDoor(self._doorB, self._doorBTargetPos) end
        if (not self._doorA or self:_isAtPos(self._doorA, self._doorATargetPos)) and
           (not self._doorB or self:_isAtPos(self._doorB, self._doorBTargetPos)) then
            self.state = "open"
            s = self.state
           
        end
    elseif self.state == "closing" then
        if self._doorA then self:_moveDoor(self._doorA, self._doorAOrigPos) end
        if self.doorType == "Double" and self._doorB then self:_moveDoor(self._doorB, self._doorBOrigPos) end
        if (not self._doorA or self:_isAtPos(self._doorA, self._doorAOrigPos)) and
           (not self._doorB or self:_isAtPos(self._doorB, self._doorBOrigPos)) then
            self.state = "closed"
        end
    end
 
    if self._wasInside and not inside and (self.state == "opening" or self.state == "open") then
        self.closeStartTime = Millisecs()
    end
 
    if self.closeStartTime and Millisecs() - self.closeStartTime >= 5000 then
        self.state = "closing"; self.closeStartTime = nil
    end
 
    self._wasInside = inside
    self._inside = false
 
   if s == "opening" then
       
        self:FireOutputs("doorOpened")
      s = self.state
   end
 
end
 
function KaraConsole:_moveDoor(door, target)
    local pos = door:GetPosition()
    local dir = (target - pos):Normalize()
    local step = dir * self.openSpeed
    if (target - pos):Length() <= self.openSpeed then
        door:SetPosition(target)
    else
        door:SetPosition(pos + step)
    end
end
 
function KaraConsole:_isAtPos(door, target)
    return (door:GetPosition() - target):Length() <= self.openSpeed
end
 
RegisterComponent("KaraConsole", KaraConsole)
return KaraConsole

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Posted

@Josh
I think it is not the code, it is that it does not save the data of the connected nodes, I notice this if I exit the editor and load it again, it does not always happen.

The save button does not work in the editor, I go back to 3D and hit save, sometimes it works and sometimes it doesn't, that's the confusion. 

image.thumb.png.cfb93907f53e38b5e462c72a1498d3aa.png

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...