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 / [SOLVED] What is the syntax for using .find for multidimensional arrays?? Or do we need to loop through the dimensions ourselves in such a case?

Author
Message
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 15th Oct 2018 14:22 Edited at: 15th Oct 2018 14:32
I would like to find the index of where a map tile was stored from a map[a,b] type array;

map[1,1] = tile1
map[1,2] = tile2
map[1,3] = tile3
map[2,1] = tile4
map[2,2] = tile5
map[2,3] = tile6
map[3,1] = tile7
map[3,2] = tile8
map[3,3] = tile9

I would like to use map.find(tile1....9), but that gives a syntax error. It apparently wants something like map[n].find(object_ID) instead.

Quote: "main.agc:2151: error: Cannot search arrays of arrays, use more dimensions to search a sub array"




...now map[mposindat,nposindat] of course does return the correct tile object ID with the above work-around doing the search myself. But am I missing something, can we not use .find for multidimensional arrays??

The author of this post has marked a post as an answer.

Go to answer

PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 15th Oct 2018 14:50
Also, sorry for these newbie questions, but I'm still learning AGK2.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 15th Oct 2018 15:01
This post has been marked by the post author as the answer.
Well, find() only works reliably on a sorted list. All the tile indices would have to be in numerical order which they wouldnt be in a tilemap.

A tilemap wont be sorted at all so .find becomes pointless anyway.

Best to simply use a nested set of compares accross x and y in the map.
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 15th Oct 2018 15:07
Ah okey, thanks Bengismo ! Yeah, the tile map is only in numerical order for as long as a single row would be. So I guess there is no good order then.

Guess I have to use the work-around code then for checking neighboring tiles etc. Not a big deal.

Login to post a reply

Server time is: 2024-04-20 04:50:28
Your offset time is: 2024-04-20 04:50:28