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
.
.
.
|