Jump to content


Photo

Are arrays passed by reference or by object?


  • Please log in to reply
5 replies to this topic

#1 Serrath

Serrath

    GMC Member

  • New Member
  • 143 posts

Posted 09 June 2012 - 11:55 AM

If I set one array equal to another, does that pass a copy of the object or does it just pass the reference to the new variable? When a function returns an array, does this pass an object or a reference? When you pass an array into a function, does it pass the object or a reference?
  • 0

#2 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3143 posts
  • Version:Unknown

Posted 09 June 2012 - 12:19 PM

In every case it passes the value stored in the array to whatever you are passing to.

Arrray[0] = 5 ;
A[1] = Array[0] ;
Array[0] += 1 ;

A[1] will still be 5
  • 0

#3 Zeddy

Zeddy

    Totally Radical Dude

  • GMC Member
  • 1798 posts
  • Version:GM8

Posted 09 June 2012 - 12:23 PM

Like Alex said, you cannot pass arrays. arr actually just gives the value at arr[0,0].

If you wish to pass an array around, either put it in an object and pass the object or use ds_lists.

Edited by Zeddy, 09 June 2012 - 12:24 PM.

  • 0

#4 Serrath

Serrath

    GMC Member

  • New Member
  • 143 posts

Posted 09 June 2012 - 01:22 PM

You can't pass arrays..? Dear lord... Can you use local arrays in scripts? i.e. Can I alter an object's arrays when I call a script from that object?

Edited by Serrath, 09 June 2012 - 01:33 PM.

  • 0

#5 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3143 posts
  • Version:Unknown

Posted 09 June 2012 - 01:43 PM

Yes and Yes. If you need the ability to pass them use one of the data structures (list for 1 dimension , grid or maps for 2+)
  • 0

#6 Serrath

Serrath

    GMC Member

  • New Member
  • 143 posts

Posted 09 June 2012 - 08:30 PM

Thanks!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users