(Aug 26, 2015, 04:42 PM)Lord Octagon link Wrote: [ -> ][quote author=Rayts5 link=topic=1167.msg12984#msg12984 date=1440596281]
[quote author=Voluptious link=topic=1167.msg12983#msg12983 date=1440596209]
[quote author=Rayts5 link=topic=1167.msg12981#msg12981 date=1440595827]
Note, careful on your variables.
local str = PackageTable(ply:RollDice(args[1], args[2], args[3]))
net.WriteString(str)
Is the same as
net.WriteString(PackageTable(ply:RollDice(args[1], args[2], args[3])))
I know that the above looks better since you store a string, but you are performing 1 extra unnecessary operation.
Its easier to read and debug if you do it this way, I do things like this aswell
[/quote]
It is, but you are moving a var to a register which is slower than just calling the retrieved thing itself. There is no need to store more stuff to our base pointer.
[/quote]
What are you on about. All these words. What's a 'var', can you eat it?
[/quote]
Low level programming, don't you worry.
(Aug 26, 2015, 05:08 PM)Spy link Wrote: [ -> ][quote author=Rayts5 link=topic=1167.msg12981#msg12981 date=1440595827]
... What? Why are you utilizing two network variables for this? It does not give sense any sense, you are making the server handle both net.Receive and net.Start lol.
Simply make 1 (or 2 if you want to) concommands on the server-side and handle the rolling and such from there. There is absolutley no need to store a network variable on the player, just store a variable on the player instead.
Note, careful on your variables.
local str = PackageTable(ply:RollDice(args[1], args[2], args[3]))
net.WriteString(str)
Is the same as
net.WriteString(PackageTable(ply:RollDice(args[1], args[2], args[3])))
I know that the above looks better since you store a string, but you are performing 1 extra unnecessary operation.
Also, in your GetNearbyPlayers function, just store 1 table instead before the function, otherwise you will keep adding tables in the stack which is generally a bad idea (unless you want it to overflow lol, I do not believe Lua had a garbage collector). At start, clear the table and then add the players to the table.
I'll go at it piece by piece since there are a few things, one thing first by no means in this script perfect and I pretty happy someone actually decided to say there was something wrong with it. Because it is by no means perfect. Also if I misunderstand you throughout the post my bad, just correct me again ^^
I presume you're talking about the net library when you say I'm handling two network variables server side. There is a if SERVER check so net strings at cached on the server and the receivers are set up on the client side. So I'm not really sure what you are getting at there. I think I have a rough idea looking at it again. I think you're talking about the use of two net strings which I agree is completely unnecessary (mentioned in comments iirc) that's due to me rethinking how it was going to be done mid way, but it doesn't make much difference performance wise. I'll make the change anyways.
I'm not networking any variables on the player, they are being index to the player. This is done so we can get there last roll if for some reason chat is cleared or the player intended to receive the role didn't see it. Literally what you describe is done next. There are two console commands, (there could be one but I was lazy, check comments ^^) that handle the rolling server side. So as you said I am storing the variable on the player and it is not being networked.
There is actually another mistake I noticed thanks for pointing it out thought I changed it. You currently cannot see who rolled, I thought I add the players name to the start. Either way you are correct here and it servers no other use than being easier to change and read.
On the note of overflowing the stack with the creation of tables. We don't have to worry about shit like that fortunately as lua runs it's gc periodically getting rid of variables it can no longer access (iirc? Correct me if need be). Though saying that your way would be better, as far I'm aware though there will be no noticeable performance difference.
I don't have a great deal of knowledge in low level programming, I'd love to learn and will probably start more when I get back. Thanks for the heads up with your points I'll make a second version incorporating your ideas. I'll post it I'm the next few days depending on timings etc..
Sorry if this came off the wrong way, this was all typed on my phone so it's hard to read back and make changes. Anyways thanks for the help I'll post a new version soonish
[/quote]
It did not come out the wrong way at all. ^^ I might have been too sharp in my first comment too, in terms of reviewing the code. What I wanted to say, was the fact that it is not necessary to use the Net library at all as it can simply be stored on the player variable; concommands are usually handled server-side after all. I can however give a super thumbs up for continuing to improve the code. Some would see that it works, and then just carry on, despite its looks.
I am not sure about how good the current gc is in Lua, but you are correct that a garbage collector removes variables which points to unused memory.
If you need help with lower level programming, also, I can help you with it. Ever since I got into low level programming (several months ago), I have started to see everything at that level. Which, is also quite useful when coding C++.