AggrorJorn Posted March 17, 2012 Share Posted March 17, 2012 I am working on a simple Tower defense tech demo and I have a little problem. I want to address a roadnode in the editor via C#. After that, I want to make a simple loop that goes though the nodes with GetEntityTarget. At the moment I search for the first road node in a level. Then I loop through the roadnodes to get a list that represents the path. The problem is, that it can not find a target in the scene, while the road nodes are deffinitly connected in the editor. //Load the first level TEntity level1 = LE.LoadScene("abstract::level1.sbx"); //Get the path TEntity currentNode = LE.FindChild(level1, "node_1"); List<TVec3> path = new List<TVec3>(); bool pathEnded = false; while(pathEnded == false) { TEntity nextNode = LE.GetEntityTarget(currentNode); if (nextNode == null) pathEnded = true; else { path.Add(LE.EntityPosition(nextNode)); currentNode = nextNode; } } Quote Link to comment Share on other sites More sharing options...
Rick Posted March 17, 2012 Share Posted March 17, 2012 TEntity currentNode = LE.FindChild(level1, "node_1"); Is that line working? Is it finding anything? Not sure if that's a C# LE thing, but normally you have to loop through entities with GetChild() and then by index not name. Then you use GetEntityKey() on each index looking for the "name" key and checking that to what you are looking for. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 17, 2012 Author Share Posted March 17, 2012 Thanks for the answer Rick. As far as I can tell, it does find the object using only FindChild. To make sure that is it correct I have its name checked //Find the correct index with GetChild TEntity entTemp = LE.FindChild(level1,"node_1");//LE.GetChild(level1, i); //After every child index has been found, use GetEntityKey to search for Object with a name if (LE.GetEntityKey(entTemp, "name") == "node_1") Console.WriteLine(LE.GetEntityKey(entTemp, "name").ToString); I see now where the problem lies. I get the entity target but that target can be null. I get a system protected memory error. I think I can find whats wrong now. Just have to find out how I can solve this. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 19, 2012 Author Share Posted March 19, 2012 How can I prevent that an entity has not target and thereby crashes the program? //Get the path TEntity currentNode = LE.FindChild(level1, "node_1"); Console.WriteLine(currentNode.ToString()); bool pathEnded = false; while(pathEnded == false) { TEntity nextNode; if (LE.GetEntityTarget(currentNode) != null) { nextNode = LE.GetEntityTarget(currentNode); Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString()); path.Add(LE.EntityPosition(nextNode)); currentNode = nextNode; } else pathEnded = true; } the log reports that it finds all the nodes now, but as soon as the target is not present, my programm crashes. Quote Link to comment Share on other sites More sharing options...
Daimour Posted March 19, 2012 Share Posted March 19, 2012 How can I prevent that an entity has not target and thereby crashes the program? nextNode = LE.GetEntityTarget(currentNode); Try to check nextNode for NULL. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 19, 2012 Author Share Posted March 19, 2012 thanks for the reply. Isn't this line doing that? if (LE.GetEntityTarget(currentNode) != null) Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted March 19, 2012 Share Posted March 19, 2012 I think he's referring to this: nextNode = LE.GetEntityTarget(currentNode); Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString()); you are using nextNode without checking that it's not NULL Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Daimour Posted March 19, 2012 Share Posted March 19, 2012 Isn't this line doing that? if (LE.GetEntityTarget(currentNode) != null) Sorry, I didn't pay attention. May be crash occurs after that loop? Or try to comment these lines out. May be the error occurs somewhere here: Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString()); path.Add(LE.EntityPosition(nextNode)); Quote Link to comment Share on other sites More sharing options...
Rick Posted March 19, 2012 Share Posted March 19, 2012 Are the links done on models vs meshes (or reverse) and you have to get parent or get child on the entity returned from GetTarget? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 19, 2012 Author Share Posted March 19, 2012 @Pixel: I am not sure I understand what you mean. If the target is null if (LE.GetEntityTarget(currentNode) != null) Then these lines shouldn't be executed nextNode = LE.GetEntityTarget(currentNode); Console.WriteLine(LE.GetEntityKey(nextNode, "name").ToString()); @Rick The script finds the models (see screenshot). And since there is no 17th node, the loop should stop. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 25, 2012 Author Share Posted March 25, 2012 Found it: instead of checking null, I now simply check: LE.GetEntityTarget(currentNode).IsValid 1 Quote Link to comment Share on other sites More sharing options...
Pixel Perfect Posted March 26, 2012 Share Posted March 26, 2012 Yeah, apologies Aggror, I answered without reading it properly, fatal mistake lol. Glad you have it fixed anyway Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 26, 2012 Author Share Posted March 26, 2012 No need to apologize Pixel, but thank you anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.