The idea is having a shelf taking in different arrays and if the first one is taken there's a boolean that says it's false and it will loop to the next Value. However if it's not taken it will say true and will make it false and executing the code
would something like this work?
Initialize:
self.drugSpotVectors = {Vector(0,-17,32), Vector(0,-5,32)}
Execution:
for k, v inpairs(self.drugSpotVectors) do if self.drugSpotVectors[v] == true then
ent:SetPos(self:GetPos() + self.drugSpotVectors[v]) ent:SetAngles(Angle(0, 90, 0))
self.drugSpotVectors[v] = false
end
end
As the experienced people can tell i'm not very experienced with tables so be easy on me.
When using a in pairs loop the second varible (in this key v) is the object that is stored in the table at that key. So in your code where you were doing self.drugSpotVectors.isTaken[v] you would really only need to be checking v. Basically in this case v would be equal to doing this self.drugSpotVectors.isTaken[k].
Thanks for reply. I changed the code based on what you said, but I still can't get it working. Is this correct?
if ent:GetClass() == "amphetamine_cooked" or "morphine_cooked" or "alcohol_cooked" or "steroid_cooked" then
if self.isFull == false then
for k v in pairs(self.drugSpotVectors.isTaken) do
if v == self.drugSpotVectors.isTaken[k] then
ent:SetPos(self:GetPos() + self.drugSpotVectors[v]) ent:SetAngles(Angle(0, 90, 0))
self.drugSpotVectors.isTaken[k] = 0
end
end
end
end
Almost, when your checking to see if its taken you would want to do this.
v == 1
Also when trying to access the vector you stored in self.drugSpotVectors using the varible k not v.
Thanks got it working now
Sorry, you need to Log In to post a reply to this thread.