|
| 06 Jun 2012 03:08 PM |
I use unpack because the function likes to change _G.Nodes's values and the values of Current nodes...
function Pathfind(S, E) --Start and End are the term numbers of each node from the _G.Nodes table
Impossible = false FinalPath = {} CurrentNodes = {unpack(_G.Nodes)} OpenNodes = {} ClosedNodes = {} Finished = false FinalPath = {} Start = S End = E ActiveNode = 1 Flipped = {} UhOh = 0
if CurrentNodes ~= _G.Nodes then error("I don't get it...") end
--Then more stuff
I get the error the second time the function runs... That doesn't even make sense...
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 06 Jun 2012 03:14 PM |
RARGH
TABLES PASS AND COMPARE BY REFERENCE |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 03:14 PM |
What?
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 03:16 PM |
| TIL that `{unpack(t)}` is a concise way to copy an array. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 03:18 PM |
This should (hopefully) explain your problem:
if {1, 2, 3} == {1, 2, 3) then print("Yeah, right") else print("While the two tables contain the same values, they are not the same table") end |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 03:24 PM |
Well, how do i make it so they are the same table? My script is really funky and values aren't fully reset in the Current Nodes table...
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 03:28 PM |
What are you aiming for here? If they're the same table, modifying one will modify both (since they're _the same table_).
Are you trying to check if the tables contain the same items? If so, why? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 06 Jun 2012 03:28 PM |
| You can't make other table into same table. You have to check points one, by one with loop. |
|
|
| Report Abuse |
|
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 06 Jun 2012 03:36 PM |
"You have to check points one, by one with loop."
Which is of course exactly why you don't want to.
You could modify __eq, but it's worth pointing out this does NOT work for using the value as a table key - unique reference objects are always unique keys (which messes up using the Roblox math types as keys, but, eh.) |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 03:45 PM |
Look in TheAI:
http://www.roblox.com/Working-with-AIs-place?id=12401170
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:01 PM |
How will looking at a place we can't see the code for help...
I don't understand why you need to check if two tables are equal. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 06 Jun 2012 04:03 PM |
| You can see his code. He made it uncopy locked |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:04 PM |
| Time to see if my roblox asset downloader works with places... |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
| |
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:06 PM |
| Upload it as a model, and I'll have a look |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 06 Jun 2012 04:06 PM |
@NXT
STOP SPAMMING YOU INEPT CAMBRIDGE UNIVERSITY ROBOTICS-CRAZY STUDENT.
Oh, and what courses did you take? |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 04:10 PM |
I don't want to make a model... :/
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:14 PM |
| I definitely do not want to open roblox. Can you just paste your entire script here? |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 04:24 PM |
Uh, ok....
BTW http://www.roblox.com/Forum/ShowPost.aspx?PostID=69386462
--[ GET TARGETS ]-- TargetType = "Red"
function GetTargets() ToSearch = script.Parent.Parent:GetChildren() local Targets = {} for i = 1, #ToSearch do --print(i .. " " .. ToSearch[i].Name) if ToSearch[i]:findFirstChild("Type") then if ToSearch[i].Type.Value == TargetType then Targets[#Targets+1] = ToSearch[i] --print(ToSearch[i].Name) end end end return Targets end
--[ CHECK CLOSEST TARGET ]--
function CheckClosestTarget(TableOfTargets)
Brick = script.Parent.Torso
if #TableOfTargets > 1 then local CurrentMag = (Vector2.new(TableOfTargets[1].Torso.Position.x,TableOfTargets[1].Torso.Position.z) - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude local Closest = TableOfTargets[1] for i = 2, #TableOfTargets do if CurrentMag > (Vector2.new(TableOfTargets[i].Torso.Position.x,TableOfTargets[i].Torso.Position.z) - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude then CurrentMag = (Vector2.new(TableOfTargets[i].Torso.Position.x,TableOfTargets[i].Torso.Position.z) - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude Closest = TableOfTargets[i] end end return Closest elseif #TableOfTargets == 1 then return TableOfTargets[1] else return nil end end
--[ CHECK CLOSEST NODE ]--
function CheckClosestNode(Brick) local CurrentMag = (_G.Nodes[1]["Position"] - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude local Closest = 1 for i = 2, #_G.Nodes do if CurrentMag > (_G.Nodes[i]["Position"] - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude then CurrentMag = (_G.Nodes[1]["Position"] - Vector2.new(Brick.Position.x,Brick.Position.z)).magnitude Closest = i end end return Closest end
------------------------- --[[ FOR PATHFINDING ]]-- -------------------------
--[[ STUFF ]--
OpenNodes = {} ClosedNodes = {} Finished = false FinalPath = {} Start = 0 End = 0
--[ TABLE INSERT FOR MY STYLE ]]--
function TblInsert(t, val) --Give it the table and the value table.insert(t, #t+1, val) end
--[ FANCY TABLE REMOVE ]--
function TblRemove(t, val, pos) --Give it the table and the value to remove OR just the position
if pos == nil then print(val) for i = 1, #t do if t[i] == val then table.remove(t, i) break end end elseif pos ~= nil then table.remove(t, pos) end
end
--[ CHECK IF IN TABLE ]--
function InTable(Table, val) Found = false
for i = 1, #Table do if Table[i] == val then Found = true end end
return Found end
--[ SET F, G, AND H ]--
function GetFGH(w)
local ParentNode = CurrentNodes[w]["Parent"]
--Node Cover may affect Score in the future
if ParentNode ~= nil and CurrentNodes[ParentNode]["G_Score"] ~= nil then CurrentNodes[w]["G_Score"] = CurrentNodes[ParentNode]["G_Score"] + (CurrentNodes[w]["Position"] - CurrentNodes[ParentNode]["Position"]).magnitude else CurrentNodes[w]["G_Score"] = 0 end
CurrentNodes[w]["H_Score"] = (CurrentNodes[w]["Position"] - CurrentNodes[End]["Position"]).magnitude CurrentNodes[w]["F_Score"] = CurrentNodes[w]["G_Score"] + CurrentNodes[w]["H_Score"]
return CurrentNodes[w]["F_Score"] end
--[ MAKE NEIGHBORS OPEN ]--
function InsertNeighbors(WhichNode)
for i = 1, #CurrentNodes[WhichNode]["Neighbors"] do CurNum = CurrentNodes[WhichNode]["Neighbors"][i]
if InTable(ClosedNodes, CurNum) == false then if CurrentNodes[CurNum]["Parent"] == nil then CurrentNodes[CurNum]["Parent"] = WhichNode TblInsert(OpenNodes, CurNum) GetFGH(CurNum) else SavedParent = CurrentNodes[CurNum]["Parent"] SavedScore = CurrentNodes[CurNum]["F_Score"]
CurrentNodes[CurNum]["Parent"] = WhichNode if GetFGH(CurNum) > SavedScore then CurrentNodes[CurNum]["Parent"] = SavedParent CurrentNodes[CurNum]["F_Score"] = SavedScore end
end
end
end end
--[[ ACTUALLY FIND PATH ]]--
function Pathfind(S, E) --Start and End are the term numbers of each node from the _G.Nodes table
Impossible = false FinalPath = {} CurrentNodes = {unpack(_G.Nodes)} OpenNodes = {} ClosedNodes = {} Finished = false FinalPath = {} Start = S End = E ActiveNode = 1 Flipped = {} UhOh = 0
print(CurrentNodes[Start]["Parent"]) GetFGH(Start) InsertNeighbors(Start) TblInsert(ClosedNodes, Start)
if Start ~= End then
while Finished == false do print(#OpenNodes) print(#ClosedNodes) UhOh = UhOh + 1 if UhOh > (#CurrentNodes)^2 then error("WHY YOU BE SUPER BIG LOOP?!?!?!") end if #OpenNodes > 0 then
F_ScoreTest = 1e+45
for i = 1, #OpenNodes do if CurrentNodes[OpenNodes[i]]["F_Score"] < F_ScoreTest then ActiveNode = OpenNodes[i] F_ScoreTest = CurrentNodes[OpenNodes[i]]["F_Score"] end end
print("Active: " .. ActiveNode) if ActiveNode ~= End then InsertNeighbors(ActiveNode) TblRemove(OpenNodes, ActiveNode, nil) TblInsert(ClosedNodes, ActiveNode) else InsertNeighbors(ActiveNode) TblRemove(OpenNodes, ActiveNode, nil) Finished = true end
else print("Out of nodes; Impossible path") Impossible = true break end
end
if Impossible == false then CurNum = End
while CurNum ~= Start do TblInsert(FinalPath, CurNum) CurNum = CurrentNodes[CurNum]["Parent"] end
TblInsert(FinalPath, Start)
for i = 1, #FinalPath do Flipped[#FinalPath-i+1] = FinalPath[i] end return Flipped else return nil end
else return nil end
end
--------------- --[ RUNTIME ]-- ---------------
--[[For Testing]]--
wait(3) while true do wait(1) print( "Closest Node:" ) print(CheckClosestNode(script.Parent.Torso)) print( "Closest Target:" ) Close = CheckClosestTarget( GetTargets() ) print(Close.Name .. " ; " .. CheckClosestNode(Close.Torso) ) Pathfind(math.random(1,#_G.Nodes), math.random(1,#_G.Nodes)) end
~Read Between The Squiggles~ |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:51 PM |
| Pasted successfully (complete with indentation) into Sublime Text. Your indentation is a mess. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 06 Jun 2012 04:58 PM |
| Your code doesn't even contain that comparison! What's the problem? |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2012 05:34 PM |
| The currentnodes is not.properly.being.refreshed and wipedbeverytime the function is called |
|
|
| Report Abuse |
|
|
lah30303
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 10027 |
|
|
| 06 Jun 2012 06:11 PM |
| I don't know if this is a good idea or not because I don't know much about what happens outside of the lua language, but couldn't you concatenate all the elements in each table into a string, then see if the strings are equal? |
|
|
| Report Abuse |
|
|
lah30303
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 10027 |
|
|
| 06 Jun 2012 06:15 PM |
| *compare the strings (I don't know if equal is the right term) |
|
|
| Report Abuse |
|
|
| |
|