![]() |
|
Problems with an emitter - Printable Version +- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk) +-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html) +--- Forum: Starfall (https://teamscm.co.uk/forum-7.html) +--- Thread: Problems with an emitter (/thread-872.html) Pages:
1
2
|
Problems with an emitter - Destiny's Player - 18-04-2015 Good time of the day to everybody who reads this. So, I have a few problems with this code. 1: It overloads and shutdowns, but that's not the main problem, I just didn't look into fixing it because of the second problem. 2: For some reason, the "if" argument near the end, that checks the "on" variable doesn't give me ANYTHING. Tried with a simple "else", tried with an "elseif On == 0", doesn't work, returns something that makes the render completely visible, not even at 200 Alpha. Also, thank you to Black and Ia for trying to help me.
RE: Problems with an emitter - Person8880 - 19-04-2015 That's because of lexical scoping.
What you want to do is make sure your local Alpha value is available to the scope above the if statement block:
RE: Problems with an emitter - Destiny's Player - 19-04-2015 Hmm... Weird. That worked, but there's still a problem with transiting information between the server and the client. It's not even zero, it's non-existent, i.e. print(On) gives absolutely nothing out, not even an empty message. RE: Problems with an emitter - Person8880 - 19-04-2015 That's because you're using a net hook to try and receive a DTVar, when a DTVar is implicitly networked in the background once set, not explicitly sent.
This bit does nothing. The net hook is for receiving network messages when using something like
Placing net.setDTVar() inside a block like this does nothing, it's not sent in the message. Only data written to the message using the net.write* functions is sent.To solve your problem, you need to rethink what's actually going on. Your code runs once, when the chip is first loaded. The client and server instances are not run at the same point in time. The client instance will load some measure of time later, depending on transferring speed of the code to each client. At the moment your code runs, the DTVar may be available and correct, or it might not. Therefore, the safe and best way to deal with this (and to detect when it changes!), is to be checking the DTVar value in the render hook so it's always using the most up to date Alpha value.
RE: Problems with an emitter - Destiny's Player - 19-04-2015 Finally figured everything out. With the help of T-16, everything finally works! And also, I had to lift my op parameter or whatever up, cause that was why my chip kept on crashing.
RE: Problems with an emitter - TheOneAndOnlyTee - 20-04-2015 I would've made it so it only sends data when either of the inputs is changed but i was rather tired and couldn't remember how. Code: time.timer("think",1,0,function()
Active2 = SendoTablo.Active
HP2 = SendoTablo.HP
SendoTablo.Active = wire.ports.Active
SendoTablo.HP = wire.ports.HP
if Active2 ~= SendoTablo.Active or HP2 ~= SendoTablo.HP then
if net.start() then
--printConsole("sending...")
net.writeTable(SendoTablo)
net.broadcast()
end
end
end )RE: Problems with an emitter - Person8880 - 20-04-2015 You do realise, that you've essentially killed the optimisation that was there. Go back to what I posted. The DTVar is set on change, propagated once and it's happy. With what you have, not only are you sending way more data than you need due to writeTable, but you're also sending redundant data every second. What I posted already worked, and it way more optimal than using writeTable and the timer. Networking Problems To spell it out, this is what write table does in pseudo Lua code:
Thus, the write table code you have is sending:
Total per send: 8 + ( 7 * 8 ) + 8 + 64 + 8 + ( 3 * 8 ) + 8 + 64 + 8 = 248 bits or 31 bytes per send every time.Now compare that to using 2 DTVars:
Total sent ONLY WHEN CHANGED: 32 + 1 = 33 bits = 4.125 bytes at the most if both values change.Input change detection problems You've also now added a completely redundant and overly complicated way of detecting input changes. The input hook was designed for this purpose.
This accomplishes changing the DTVars (and note that the DTVars only network if the value you are providing is different to what's already stored, this is their entire purpose!) without a clunky timer or a table or checking against other values.So, back to what I posted before with the added tweak to the active network value:
Nothing is more deterring than when someone you are trying to help completely ignores what you've posted and ends up with something far worse and a load of misconceptions about what the code is doing.I hope that you will not ignore this post and understand why what you have now is much, much worse. If you have any questions about what I've written please ask rather than ending with a chip that steadily declines into unmaintainable. RE: Problems with an emitter - Destiny's Player - 20-04-2015 First of all, I'm sorry that it looked like I ignored your post. I really didn't, I just couldn't get it to work by myself even with your advice, and I didn't want to wait another day for another helpful post, so I just asked some people on the server, and this was the result. I just got too happy that this chip finally worked SOMEHOW that I slightly phased out. Secondly, I totally see that the variant you've made is better. Can't try it out right now, as I'm so tired that I had to force myself to write this post now, and not tomorrow, but from the first glance, I see the difference. Thirdly: Just wanted to say thanks for still trying to help, even though it looked like I completely ignored you. I think that you, as a much more capable programmer, should know how much it goes into your head when something you've been trying to do for several days without any results finally works at least somehow. Or is it just me? RE: Problems with an emitter - TheOneAndOnlyTee - 21-04-2015 same, I should've looked at your code and tried to help him get that working. also one question, are DTVars better than tables for screens? (assuming i was only sending ~12 variables) RE: Problems with an emitter - Destiny's Player - 21-04-2015 ...aaaaand the code you've given me doesn't work. Doesn't even show the render for a moment. In fact, it appears like it doesn't run on the server at all, i.e. there's no instances when I check it with the profiler, and I really have no idea why it doesn't work. From what I see, DTVars simply don't work for me, they never return anything. Sorry if I sound as a douchebag, but that's one way I can tell people that stuff doesn't work. And also I'm slightly angry due to some RL issues, so don't mind me if I do act like a douchebag for some time now... |