• Shared variables?
    2 replies, posted
i am sure that the answers in front of my eyes, but currently I am mostly messing around and trying to learn lua independently. I am attempting to have one script set a value for a variable, take "x" for an example, at a specific point. Then, another script, would test to see if "x" is a particular example. Again, take "1" for an example. I attempted to do so using local name,addon=...; and addon.myvar = "true" but am recieving the error "attempt to index upvalue 'addon' (a nil value)". How could I resolve that, and accomplish my goal? If further clarification is required: In this particular example I am having them put an object into another object, and testing to see if the second object has the third object in it via another script Code for the first script: [CODE]AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel( "models/props_interiors/pot02a.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.isRunning = false local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end self.isBaking = false self.finishBakeTime = 0 end function ENT:StartTouch(ent) if ent:GetClass() == "dough" and self.isBaking == false then self.isBaking = true ent:Remove() --self.finishBakeTime = CurTime() + 0 --else if ent:GetClass() == "bread" and self.isBaking == true then --ent:Remove() --end end end function ENT:Think() if self.isBaking == true then self:SetColor(Color(255,0,0)) local name,addon=... addon.myvar = "true" else self:SetColor(Color(0,0,255)) end --if self.isBaking == true then --if self.finishBakeTime <= CurTime() then --Done! --self.isBaking = false --local bread = ents.Create("bread") --bread:SetPos(self:GetPos() + Vector(0, 25, 0)) --bread:Spawn() --end --end end [/CODE] Code for second script, where I wish to access a variable in the first script: [CODE]AddCSLuaFile("shared.lua") include("shared.lua") local name,addon=...; function ENT:Initialize() self:SetModel( "models/props_c17/furnitureStove001a.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.isRunning = false local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end self.isActive = false self.finishActiveTime = 0 end function ENT:StartTouch(ent) if ent:GetClass() == "cooker" and addon.myvar == "true" then self.isActive = true ent:Remove() self.finishActiveTime = CurTime() + 10 --else if ent:GetClass() == "bread" and self.isBaking == true then --ent:Remove() --end end end function ENT:Think() if self.isActive == true then self:SetColor(Color(255,0,0)) else self:SetColor(Color(0,0,255)) end if self.isActive == true then if self.finishActiveTime <= CurTime() then --Done! self.isActive = false local bread = ents.Create("bread") bread:SetPos(self:GetPos() + Vector(0, 25, 0)) bread:Spawn() end end end [/CODE]
You can't access locals from other files, and ...; is not valid notation. What do you want the variables of name and addon to be?
In script 2, I want to make sure that when the player is putting the pot into the stove, the player placed dough into the pot. The first script includes the information about the player placing the dough into the pot, I want the second one to use that information.
Sorry, you need to Log In to post a reply to this thread.