Raised This Month: $12 Target: $400
 3% 

Copying Dynamic Arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 12-10-2010 , 03:35   Copying Dynamic Arrays
Reply With Quote #1

For copying a dynamic array into another function, could you simply do...

Code:
public CmdSortMaps( id )
{
     SortMaps( g_aMapName, g_aMapDifficulty );
}

SortMaps( Array:mapname, Array:difficulty )
{
     //stuff
}
Or would you have to create a function that creates a new array and copies it's items one by one?

(i.e.) Would using the above code only pass the reference to the same array, and thus not a completely new dynamic array.
shadow.hk is offline
Send a message via MSN to shadow.hk
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-10-2010 , 04:51   Re: Copying Dynamic Arrays
Reply With Quote #2

Dynamic arrays are not associated by the variable directly, but by the variable's value.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-10-2010 , 12:50   Re: Copying Dynamic Arrays
Reply With Quote #3

It's similar to using a pointer.
__________________
fysiks is offline
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 12-11-2010 , 06:34   Re: Copying Dynamic Arrays
Reply With Quote #4

So... yes, I'd need to create a new array and copy it's contents over manually?
shadow.hk is offline
Send a message via MSN to shadow.hk
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-11-2010 , 06:36   Re: Copying Dynamic Arrays
Reply With Quote #5

No, you just pass the array index, and all gonna works fine.

new Array:a
a = ArrayCreate()

stock MakeSomeThingWithArray(Array:b, ...)
{
new size = ArraySize(b)
}

somefunction()
{
MakeSomeThingWithArray(a, ..)
}
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode