Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / V2 array question

Author
Message
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 27th Oct 2014 12:42 Edited at: 27th Oct 2014 12:42
Could anyone supply me with the syntax for the array.swap command when handling multidimensional arrays? I've searched the help but the only reference to it I can find is

Quote: "Misc
There are some additional array commands that don't fit in the above categories, they are .swap(index1,index2) to swap two elements in an array (including types and multidimenional arrays) and .reverse() to reverse the elements in an array."


Using a 2-dimensional array of a type, I'm trying to swap two elements, e.g.



"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 27th Oct 2014 15:48
swap() can only swap within the same dimension, so you could swap [1,2] and [1,3] by doing giSpriteTiles[1].swap(2,3) or you could swap the arrays [1] and [2] by doing giSpriteTiles.swap(1,2). To do what you want in your example you would have to use the normal method of saving one in a temp variable and switch them manually.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 27th Oct 2014 16:31 Edited at: 27th Oct 2014 16:34
Quote: "swap() can only swap within the same dimension"

its only possible if Paul overload with swap([a1,a2],[b1,b2]) ...
if type is same it should be possible.

@Paul
cut,copy,paste would be a nice to have in array.
array[1,2].cut
array[2,3].paste

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 27th Oct 2014 16:53
Thanks Markus but that was the first command I tried; no joy.

"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 27th Oct 2014 17:54
ok, i just mean it can be realise with overload of swap function from paul,
and than i had the idea with cut,copy,paste.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 27th Oct 2014 18:33
Quote: "swap() can only swap within the same dimension, so you could swap [1,2] and [1,3] by doing giSpriteTiles[1].swap(2,3) or you could swap the arrays [1] and [2] by doing giSpriteTiles.swap(1,2). To do what you want in your example you would have to use the normal method of saving one in a temp variable and switch them manually."


Ah, ok. Thanks Paul.

"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 27th Oct 2014 19:39
Markus, absolutely - that's a good idea.

"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2014 00:46
Just have an index array and swap the indices. Never swap the data unless you are absolutely forced to, which in my experience is never.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 28th Oct 2014 08:23
@JimHawkins , Paul
if we could use by reference also in array it can be fast
swapping data blocks.

function MySwap(ref a[,] as ttype)

//its early in this morning here
local t as ttype
t = ref a[1,2]
a[1,2] = ref a[2,3]
a[2,3] = ref t

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2014 09:05
That's a better way than moving data!

-- Jim - When is there going to be a release?
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 30th Oct 2014 11:51
Not hijacking this thread, just didn't want to start a new post for a simple question:

in AGK2, how do you delete an array? In AGK1, you could use undim, but it seems that the DIM commands are depreciated.

If I have arrays within arrays, e.g. ARRAY[x].subarray[y].something, is there a way to delete ARRAY, without any memory leaks?

Thanks,

James
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Oct 2014 13:58
Only Paul can really answer this.

In an ideal world these would be objects which could be created and destroyed. Maybe that's possible, but I think not.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 30th Oct 2014 17:19 Edited at: 30th Oct 2014 17:23
@Jambo B
i know only this way.

Quote: "
a as integer[100,50]
a[0].length=0
//a.length=0
do
print(a.length)
print(a[0].length)
print(a[1].length)
if GetPointerPressed() then exit
sync()
loop
end
"


AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Login to post a reply

Server time is: 2024-04-23 19:05:05
Your offset time is: 2024-04-23 19:05:05