Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:30:36+00:00 2026-06-17T21:30:36+00:00

I have an array (in a UnityScript file for Unity3D) which has checkpoints as

  • 0

I have an array (in a UnityScript file for Unity3D) which has checkpoints as GameObjects, and I am trying to write a function to swap them. So I have

public var cps: GameObject[]; //Initializes correctly

function swap(o1:GameObject,o2:GameObject)
{
    var TempGO:GameObject = o1;
    o1=o2;
    o2=TempGO;
}

swap(cps[0],cps[1]); // nothing happens here.

Should I use pointers (not sure if they exist in js) or something else?

p.s.: I am actually trying to do a sort between them, based on their distance to a certain point, so any other suggestions would also be appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:30:38+00:00Added an answer on June 17, 2026 at 9:30 pm

    Javascript passes everything by value, you can’t pass things by reference, and there are no pointers. Thus, if you want to swap two elements, you’ll need to give it the array and the indices:

    function swap(var arr:GameObject[], var i, var j) {
        var temp:GameObject = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    

    and call it like

    swap(cps, 0, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array of 0's and 1's. And I need a function which return
i have array like below which is sorted by array_count_values function, Array ( [Session
I have array of strings, String[] data and it's 10 elements has value P
I have array of objects. I want to write method wich i will use
I have array of objects: var aoo = [{},{},{},....{},{},{}]; I need a optimized function
I have array of mobile numbers, around 50,000. I'm trying to process and send
I have array of objects form AR I want to rarefy them, with limit.
I have an array that is a object which I carry in session lifeFleetSelectedTrucksList
I have array like this: array('1224*', '543*', '321*' ...) which contains about 17,00 "masks"
I have array like below the page. I want to find array number which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.