I can't grasp the topic of unique entities. This time it's a 'time' value that requires every drug lab to be independent.
function ENT:Draw()
self:DrawModel()
self.time = 0
print(self.time)
end
function ENT:Think()
net.Receive("sendCurTime",function()
self.time = net.ReadInt(32) -- This right now sets time to 5 seconds but in the draw function it still prints 0
timer.Create("myTimer", 1, self.time, function()
time = time - 1
end)
end)
end
end
Somehow i cannot access and change self.time outside of draw.
In ENT: Draw it still prints 0 because everytime you call ENT:Draw you reset the variable to 0
Because you remake the variable everytime you call ENT:Draw
So where should i put the self.time then?
You're not supposed to define net.Receive functions inside other functions, unless you know what you intend to do, which you clearly do not, so just follow what the wiki tells you.
Getting frustrated about this is completely normal if you do, there's a steep learning curve and eventually it'll make more sense, just keep writing.
Thanks, i'm extremely frustrated right now. Lol. Thanks for the encouragement.
You can initialize variables using ENTITY/Initialize, or set the variable on `ENT` instead and it'll be accessible from all instances of said entity.
Your net.Receive needs to be outside the draw hook, you're also going to have to send the entity in the net message to set the variable on.
You could skip doing both of the above by using Entity/NetworkVar or NWVars considering it looks like you've made this entity.
I have little to no experience how NetworkVar works. From what I understand i'm supposed do this in shared?
function ENT:SetupDataTables()
self:NetworkVar( "Float", 0, "myMorphine_cooked" )
self:NetworkVar( "Float", 1, "myMorphine_uncooked" )
end
And then i just call for it in init and client? I'd also appreciate any tips to avoid wasting too much time on this simple topic
This is fine.
The names you give it are simply for the setters and getters, just make sure they're semi unique. I don't understand what you mean by that second bit of code.
You don't cook morphine..
Since the name of my table is MyMorphine_uncooked
Do i call self:SetMyMorphine_uncooked() to set it's value and self:GetMyMorphine_uncooked() to get it's value?
It isn't a table, it's just the name of the netvar.
You used "myMorphine_uncooked" in the code above, not "MyMorphine_uncooked". Otherwise yes.
`self` is just a variable, inside `ENT` functions it's just the entity that it's being called on. Whether you use `self` or not depends on where you're calling it, if it's inside an `ENT` function then yes.
Oh I got it, thanks alot!
Sorry, you need to Log In to post a reply to this thread.