ID:2025256
 
(See the best response by Multiverse7.)
Code:
world
New()
..()
spawn(world.tick_lag)
align()
proc
align()
for(var/mob/M in world)
spawn while(M)
if(!M){return}
var/a=winget(M,"Main","pos")
var/chatx=text2num(copytext(a,1,","))
if(!M){return}
var/chaty=text2num(copytext(a,findtext(a,",")+1))
winset(M,"Output","pos=[chatx+14],[chaty+672]")
winset(M,"Input","pos=[chatx+103],[chaty+799]")




Problem description:

I Have a transparent chat box as a screen obj then i got a Output&Input in the interface that i made transparent so as you chat they look like they are fitting perfectly on the chat box in which they do and the code above keeps the input and output aligned.


my question is, is there a more Efficient/Faster/cleaner way to do this.





is there a more Efficient/Faster/cleaner way to do this.

Not on the server, no. You can do this on the client, though using javascript.
Best response
You can start by not looping through every single mob in the world. NPCs don't have clients or chat boxes, so the world will be full of errors right when it starts.

You should never be modifying all instances of something in a loop if you care about efficiency. Instead, modify the New() for the object types. Try to work with the engine, not against it.

Procs like winget() and especially winset() tend to be relatively slow, but that's to be expected because the server is telling the client what to do. The frequency of updates for interface changes due to winset() is limited to give things like the map and output updates a higher priority in network communication.

The more proc calls you make, the more communication is required, so to be more efficient, it's best to limit the number of proc calls.

If you are able to cram more information into a single proc call, then you should. Both winget() and winset() give you this option, but each use a somewhat different syntax for specifying multiple controls. I think this is a feature that is overlooked too often.

For example, you could do this:
winset(M, null, {"
Output.pos=
[chatx+14],[chaty+672]
Input.pos=
[chatx+103],[chaty+799]
"}
)

Also, notice that in this example, semicolons are not needed, because in the multi-line string format, new lines are interpreted literally.

See the skin reference for more details on the syntax of winget() and winset().
Looping through world for anything where you aren't looking to affect say at least >25% of the instances in the world is almost always a huge mistake! While looping is relatively fast most game worlds can have very high instance counts making avoiding looping through world relatively important!

Keeping lists of things like connected clients or mobs with clients (and making sure you null the list's reference in the Del() of the mob/client for garbage collection) will give you much more efficient performance at an very small cost in memory.