• Trying to fire output on an entity, but failing hard
    3 replies, posted
Lua noob training my way up (as of tonight) and I've hit a wall while making an entity for my map. [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function ENT:Initialize() floorCurrent = 0 floorTo = 0 elevator = ents.FindByName(elevatorName) end function ENT:KeyValue(key, value) if key == "doorprefix" then doorPrefix = value return end if key == "elevatorname" then elevatorName = value return end end function ENT:AcceptInput( name, activator, caller, data ) if (name == "goto") then local floorCurrentDoor = ents.FindByName(doorPrefix..floorCurrent) elevator:Fire("setposition", data, 0) end end function ENT:OnRemove() end[/lua] [code][lua\entities\elevator_controller\init.lua:27] attempt to call method 'Fire' (a nil value) ][/code] What have I done wrong, where should I improve and what code criticism can you offer.
you can try this [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function ENT:Initialize() self.floorCurrent = 0 self.floorTo = 0 end function ENT:KeyValue(key, value) if key == "doorprefix" then self.doorPrefix = value end if key == "elevatorname" then self.elevator = ents.FindByName(value) end end function ENT:AcceptInput( name, activator, caller, data ) if (name == "goto") then local floorCurrentDoor = ents.FindByName(self.doorPrefix .. self.floorCurrent) self.elevator:Fire("setposition", data, 0) end end function ENT:OnRemove() end [/lua]
[lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function ENT:Initialize() self.floorCurrent = 0 self.floorTo = 0 end function getKeyValue(ent, key) return ent:GetKeyValues().key end function travelDelay(floorCurrent, floorTo) return ((floorTo-floorCurrent)*getKeyValue(elevator, "movedistance"))/getKeyValue(elevator, "speed") end //KeyValues function ENT:KeyValue(key, value) if key == "doorprefix" then self.doorPrefix = value end if key == "elevatorname" then self.elevator = ents.FindByName(value) end if key == "movedelay" then self.moveDelay = value end end //Input function ENT:AcceptInput( name, activator, caller, data ) if (name == "goto") then self.floorTo = data if (self.floorCurrent!=self.floorTo) then print(self.doorPrefix) local floorCurrentDoor = ents.FindByName(self.doorPrefix .. self.floorCurrent) floorCurrentDoor:Fire("SetAnimation", "close", 0) self.elevator:Fire("SetPosition", floorTo, moveDelay) end end if (name == "updatefloor") then self.floorCurrent = self.floorTo end end function ENT:OnRemove() end[/lua] For some reason now my door prefix value is returning nil, so I am stuck again.
Sorry, you need to Log In to post a reply to this thread.