The Daily Click ::. Forums ::. Klik Coding Help ::. Check the value of any array cell.
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
12th April, 2012 at 12/04/2012 04:45:15 -

Hey all,

When working with arrays, is there any way to achieve the following? (I have it set up as a grid on the frame.)

If value of ANY XYZ array spaces == 1
+ 'Object' is NOT within this space
-> set the value to 0

I know you can check the value of an array space by checking the XYZ, but I am wondering if it is possible to check all of them by their value. Then if any of the spaces values equal 1 and 'object' is not within it (this will check the X and Y values) then set the value to 0.

So in a nut shell I want it to detect where the 'objects' are in the grid using the array and set the value of the grid cell they are in to 1 and every other grid cell to 0.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
12th April, 2012 at 12/04/2012 10:39:30 -

So you want to check every slot in the array, and if the value is 1 plus there is no object in that space, set the value to 0?

The only way to check every slot, is with a fast loop. Run this loop as many times as you have squares in your grid. Then, check if there is an object at those particular grid co-ordinates and set the value depending.

If you need help with fastloops, let a brother know.

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
13th April, 2012 at 13/04/2012 03:03:23 -

Thanks for your reply, Chris. Yes that's exactly what I want to do.

I know fastloops but I can't seem to get a system to work for checking through the array. Are you able to kindly list out the events for a system that does this for me?

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
13th April, 2012 at 13/04/2012 06:33:14 -

I'll just make an example when I get the time. Tomorrow hopefully. If you can send me your mfa, that would speed up the process...

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th April, 2012 at 13/04/2012 14:27:59 -

I think that sounds very inefficient and slow. Assuming the majority of grid squares are empty, it should be more better to just set all values to 0 using the "clear array" action, and then run a ForEach loop for each object to set the occupied cells to 1.
Perhaps better still, you could detect when the objects move from one cell to another, and only then update the array.

 
n/a

Alonso Martin



Registered
  29/12/2010
Points
  294
13th April, 2012 at 13/04/2012 15:20:40 -

As it was suggested, you could use a loop to check for x that just executes another loop to check for y.

However, why are you using an array? Is it a level editor or a pattern array? Or are you using it to store data? I ask because you could use either the INI++ or the AssociativeArray to make things more efficient. You could perform a search with the INI++, or do a single un-nested loop to match all array keys with a root name (eg. all keys beginning with "item_") with the AssArray. They are both very flexible, and generally a better option than the array.

 
www.hfalicia.com
www.alonsomartin.mx

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
15th April, 2012 at 15/04/2012 12:29:45 -

Just so you know, I didn't make an example for you. Sketchy's method makes much more sense.

Let us know why you're using an array in the first place and maybe I'll whip something up though.

 
n/a

nivram



Registered
  20/07/2006
Points
  171
15th April, 2012 at 15/04/2012 16:30:41 -

How about the Easy Grid Object? Most of the work is done for you.

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

vetmora120



Registered
  07/01/2010
Points
  273
16th April, 2012 at 16/04/2012 00:06:18 -

Thanks for all the help here guys, much appreciated. Yeah I'll try Sketchy's suggestion and see if that works for me, otherwise I'll try the Easy Grid Object as Marv suggested.

PS: Sorry for the late reply, I was away over the weekend

 
n/a
   

Post Reply



 



Advertisement

Worth A Click