Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jason87 · Jun 06, 2013 at 02:58 AM · arraybuiltin array

Compare indices in an array of Vector2s

Hello everyone! I am in need of some assistance.

I've been attempting to compare indexes inside a vector2 array for about a week now and just cant seem to figure it out. What I am trying to do is both sort an array of vector2's, and then compare one index to the next to check for duplicates, and then delete the duplicate, all in efforts to display all the tiles a character can move to with the given amount of movement points left.

Here is the code:

 #pragma strict
 
 var movesLeft: int;
 var listOfMoveableTiles = new Vector2[100];
 var startTile: Vector2;
 
 function Start ()
 {
     FindAllMoves(movesLeft,startTile);
 }
 
 function Update () 
 {
 
 }
 
 function FindAllMoves(movementLeft: int, tile: Vector2)
 {
     for (var i = 0; i < listOfMoveableTiles.Length; i++)
     {
         if(movementLeft > 0)
         {    
     
             listOfMoveableTiles[i] = tile;
     
             movementLeft-=1;
     
             FindAllMoves(movementLeft, Vector2(tile.x, tile.y + 1) );
             FindAllMoves(movementLeft, Vector2(tile.x, tile.y - 1) );
             FindAllMoves(movementLeft, Vector2(tile.x + 1, tile.y) );
               FindAllMoves(movementLeft, Vector2(tile.x - 1, tile.y) );
           }    
           else
           {
           DeleteDupes();
           }
       }
    
 }
 
 
 function DeleteDupes()
 {
     //insert code to sort array
     
     //Debug.LogError(tilePos);
     
 /    var j: int = 1;
     
     for(var i in listOfMoveableTiles)
     {
         if(listOfMoveableTiles[i] == listOfMoveableTiles[j])
         {
             //remove listOfMoveableTiles[j]
                     i++;
                     j++;
         }
         
         else
         {
                     i++;
                     j++;
         }
     }
 }
 
 function GetMoveableTilesArray()
 {
     return listOfMoveableTiles ;
 }


I started with javascript arrays but figured it would be much better to use the builtin arrays. been racking my head over it for a bit. Just wondering if anyone can point me in the right direction. Many thanks!!

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Jun 06, 2013 at 04:33 AM 0
Share

It's .length not .Length, just FYI :)

avatar image fafase · Jun 06, 2013 at 05:01 AM 0
Share

What you are trying to do is a simili A* algorithm. You need to use a class of cell where the class contains a boolean that informs if it has been used already. I would think your function goes in an endless recursion since you are calling it inside and it will call itself again and again. Also, comparing object of class is easier since you can compare the reference ins$$anonymous$$d of the value (more accurate).

try with a simple

 class cell{
    var position:Vector2;
    var visited : boolean;
 }

When starting the search you set them all to false and start iterating checking first if it has been visited already and setting to true.

You may look there for more advanced info: http://unitygems.com/astar-1-journeys-start-single-step/

avatar image Fattie · Jun 06, 2013 at 08:02 AM 0
Share

THERE ARE NO APOSTROPHES IN PLURALS. NEVER.

avatar image Benproductions1 · Jun 06, 2013 at 08:07 AM 0
Share

@Fattie
Damded english language!! :P
"There are no aportrophe's in plural's" does just look wrong

avatar image Fattie · Jun 06, 2013 at 08:09 AM 0
Share

Lol quite right. Also the OP did not know the plural of "index."

Here's a cartoon on incorrect apostophes ... the last frame

http://achewood.com/index.php?date=09122008

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Does Initialising Built-In Array of Classes Require Constructor? 1 Answer

How do I copy an Array class array into a builtin array? 1 Answer

"InvalidCastException" with MeshFilter from JS Array to builtin array. 2 Answers

Sorting builtin arrays 2 Answers

Is there a way syntactically to assign all the values of a builtin array in one command? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges