cassius Posted June 22, 2015 Share Posted June 22, 2015 Hi What is the code for referencing all the objects placed in the world? or any one object in particular. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted June 22, 2015 Share Posted June 22, 2015 Looping over the world entities and checking names. I think world->entities is the list you want to loop over. Quote Link to comment Share on other sites More sharing options...
cassius Posted June 22, 2015 Author Share Posted June 22, 2015 Would findchild work? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
drarem Posted June 22, 2015 Share Posted June 22, 2015 What I did awhile back was create a class with an array, loop through each entity and assign to the array. Then made a function to either find the 'player' and assign to array element. In the latter case I set up a #define and made it match it, so I could just do this: #define player = 01 // --- find where player is as entity and // --- set ent[player] = entity player ent[player]->SetPosition(0,0,0); Then I created methods to act on the entity such as setposition, getposition, etc. I wanted to keep everything in the class and portable, you may choose to handle it differently. Quote Link to comment Share on other sites More sharing options...
Roland Posted June 22, 2015 Share Posted June 22, 2015 Looping through all entities in the World // used somewhere inside a class // assuming you have a pointer to the world for_each( world->entities.begin(), world->entities.end(), [this](Entity* e) // 'this' may be needed or not depending on what you will do with the 'e' entity { // e is pointer to current entity // do what you need to do }); 1 Quote AV MX Linux Link to comment Share on other sites More sharing options...
Rick Posted June 22, 2015 Share Posted June 22, 2015 Could use new C++ features to make it easier too: This should work: for(auto e : world->entities) { } 1 Quote Link to comment Share on other sites More sharing options...
cassius Posted June 22, 2015 Author Share Posted June 22, 2015 At the moment I place entities by code if I need to reference them. background objects are less important. I am debating now as to which is the most economical way to work,My existing method or one of the above.In le2 I used Blitzmax and that had a specific function for referencing entities placed in editor. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Roland Posted June 23, 2015 Share Posted June 23, 2015 Could use new C++ features to make it easier too: This should work: for(auto e : world->entities) { } Yeah. Even better. I'm starting to get to get old forgetting about the latest stuff. Thanks Quote AV MX Linux Link to comment Share on other sites More sharing options...
cassius Posted June 23, 2015 Author Share Posted June 23, 2015 I just did a google serch for "auto" gut didn't understand it. What code would it replace if I were to use it. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted June 23, 2015 Share Posted June 23, 2015 auto just picks the type for you. You don't have to worry about knowing the type (like int, float, string, or if it's a class instance). It can just make it easier to type because you are telling the compiler to work that out for you while it compiles. You can think of it as just being lazy . The main idea with the for loop is doing the : list part because it saves you from having to worry about the stl stuff (.begin(), .end(), iterator stuff which makes teh code look more confusing. Quote Link to comment Share on other sites More sharing options...
cassius Posted June 23, 2015 Author Share Posted June 23, 2015 Well that's a better explanation than any I found on google.Thanks Rick. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ 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.