-
Button index?
I have a button object. I used duplicate and have 10 columns and 10 rows.
This button seems to be an array as I use at start of frame:
Set Alterable Value A Random(10)+1
Change Text to Str$(Alterable Value A( "Button" ))
This gives my a 100 buttons with a lot of different numbers. I use this for a simple Math game.
The grid could be like this:
1 2 3 4 6 5 6 5 4 3
5 6 7 5 4 9 8 7 4 3
9 8 9 8 9 2 3 4 5 2
4 5 6 7 5 1 3 4 5 6
1 2 3 4 6 5 6 5 4 3
5 6 7 5 4 9 8 7 4 3
9 8 9 8 9 2 3 4 5 2
4 5 6 7 5 1 3 4 5 6
1 2 3 4 6 5 6 5 4 3
5 6 7 5 4 9 8 7 4 3
Then a sum appears in a text box and you click on a button(s) and get the right sum. If the sum is 4 then you could click on 1 and 3! Those two buttons then disappear. ( This idea is not mine) I´m just trying to implement this using MMF2.
Now I want to add an extra bit - if all the numbers in a row or column are cleared then you get a bonus. In Visual Basic I would use index of the button array. Which is the best way of addressing an individual button?
Keli
-
Re: Button index?
You would Spread Value 0 in an Alterable Value of the buttons, so each has a unique ID. Then you can loop through them in a fast loop. On loop AND Alterable Value of Button = Loop Index AND whatever other conditions.
However, someone will come on here and say use the ForEach object. I guess try out ForEach, it might be able to do what you want.
-
Re: Button index?
Well, seeing as the ForEach object is exponentially faster than the other method, and that it can support looping through buttons, I think it would definitely be the better option. ;)
-
Re: Button index?
Hi
Thanks both for your good help. Do you know of any examples?
Keli
-
Re: Button index?
Examples come with the For Each object...
-
Re: Button index?
ForEach is also buggy and unreliable.
-
Re: Button index?
It is? I didn't know that. Can you explain what and how it is buggy. I would appreciate it.
Thanks
Marv
-
Re: Button index?
I had problem putting it into my games because it runs the ForEach action last, so you cannot do it mid-event. After finally getting it to work in EXE, it ended up being SLOWER than if I had done it with alterable values and fast loops. I kept the ForEach loop there, it was all working, and I exported to flash, and my whole game just was a mess. Actives were spawning randomly, nothing was working, I couldn't even identify what was wrong because of how messed it was.
Overall I've had terrible experiences with ForEach every time I've used it, about 3 times. I will not be using it again.
-
Re: Button index?
Oh, ok and thanks Eliyahu.
Marv
-
Re: Button index?
Hi Keli,
I've added an example mfa file in thefile archive for your reference, hopefully it will help you!
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=217461#Post2174 61
It works out once a full row of boxes has been destroyed.
Any problems let me know.
I just realised you wanted columns AND rows! You can use the same principal for columns also, I'm sure you can figure it out ;)
Have fun!
-
Re: Button index?
Eliyahu, do not suggest not using an object just because you could not get it to work correctly. If you have a problem, then report it with an example. Many people have had success and better results with the object; so I am curious as to why it does not work for you...