of     1   

BJCarpenter
#221191906Thursday, July 13, 2017 5:54 AM GMT

I have a dumb "fill" search looking for any legal path to a target city, in a local script, checking nodes on the Server. There is noticeable lag once it must check over 50 nodes. Is this because I am constantly switching between running a line of code localy, then checking a variable (a Part) on the Serer side, because I have local versions of some of the same information..... Does it cost more thru-put to query a Server's Part's Property, as opposed to a Local Part (From a Local script)? Or can anyone improve the search? (Or are the prints creating lag? (I didn't think of that...)) local searchNo = 0 -- already searched? local List = nil -- for passing table reference of neighbour tables local found = false function searchFor(Origin) --create table local neighbours = {} -- neighbours of a hex List = neighbours -- makes the local list, global uncover(Origin) -- fills "neighbours" with any neighbouring nodes via List for i,v in next, neighbours do if found then break end if Globe[v.Name]:FindFirstChild("Income") and Globe[v.Name].Owner.Value == Team then found = true CellFound = v return else if Globe[v.Name]:FindFirstChild("Cannon")or Globe[v.Name]:FindFirstChild("Dock") then --- or v:FindFirstChild("DockFactory") then searchFor(v) end end -- goal or path? end -- loop end -- function function InitSearch() found = false searchNo = searchNo + 1 -- new search bit.Velocity = Vector3.new(searchNo,0,0) -- .Velocity.x used as a marker for "Already searched". end function searchForSupply(Origin) if Origin:FindFirstChild("Income") and Origin.Owner.Value == Team then found = true return end InitSearch() --print("Origin in search for Supply) ", Origin) searchFor(Origin) end . . . if Hex then LastHex = Hex --print("Before Search. Hex = ", Hex) Subject = LastHex:FindFirstChild("Cannon") if Subject then --Cannon print("Mode = ", Mode) -- if Subject.C.BrickColor == PlayerColor then print("BBBBBBBBBIIIIIITTTTTT", bit) searchForSupply(bit) -- bit is a local version of Hex if found then Mode = 1 -- go into Pick-up cannon mode else Mode = 4 -- out-of-supply cannon move print("MODE 4444") end . . .
BJCarpenter
#221196488Thursday, July 13, 2017 7:13 AM GMT

.
nullfeels
#221196897Thursday, July 13, 2017 7:22 AM GMT

tldr; (not all of it anyways) Constantly querying the server can certainly create network lag, but what also creates lag is iterating over a large collection without using a wait... If the loop takes long enough to execute it can even cause the serve to hang completely.
Brick_man
#221200061Thursday, July 13, 2017 8:37 AM GMT

Yea using a wait() would probably help in your case. If you don't want to wait() every part you can use something like this in your loop: if i%20 == 0 then wait() end --That will make it so every 20 parts it will wait(), for example ~ Brick_man, Owner of Brickman Nation ~
nullfeels
#221201396Thursday, July 13, 2017 9:21 AM GMT

^^ Yeah, good idea.
BJCarpenter
#221215768Thursday, July 13, 2017 3:42 PM GMT

The wait()s won't work, because the lag occurs when moving the cursor to a new node, and the search figures out if it is a legal move; in order to change the cursor to "Yes, legal', or "no, this is not an option", so that lag would just be longer. If the network communication is causing it, then having all info available localy ought to solve it. I was just being lazy..... Thanks, Brian

    of     1