The Daily Click ::. Forums ::. Klik Coding Help ::. Retrieving Highest value...
 

Post Reply  Post Oekaki 
 

Posted By Message

erghhhhx



Registered
  15/11/2007
Points
  311

Mushroom
11th July, 2009 at 23:39:10 -

...And sorting objects.

Let's say I have 5 different objects (Not that it matters, but they're counters), and I want to position them sorted.

Like this.

Obj1 (alt val a = 9)
Obj2 (alt val a = 7)
Obj3 (alt val a = 3)
Obj4 (alt val a = 0)
Obj5 (alt val a = 0)

Someonewannahelp?

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
11th July, 2009 at 23:44:08 -

Have a lookie here: http://en.wikipedia.org/wiki/Bubble_sort

Certainly one way to do it. Though you may have to use some sort of list object to do it easily since instance selection is the biggest pain on the face of the MMF2.

Or if you have an idea of what range the values will generally be in, you could simply sort them by comparing the value.

Object's Value A = 1
>Mark for position in first row.

Object's Value A = 2
>Mark for position in second row.

There are probably a few ways to do it, but to know the best way it might help to know a little more about your setup.

EDIT: If they're counters, you could try this. Name each one something like "Counter 0" "Counter 1" "Counter 2" etc.

COUNTER CHANGED = 1
>>Start loop number of counters - 1 times.
>>Set COUNTER CHANGED to 0

On loop
+Counter SAVED VALUE (initially 0) is greater than counter loopstep + 1
>>Set SAVED VALUE to loopstep + 1

On loop
+Counter SAVED VALUE is less than counter loopstep + 1
>>Switch values via third counter (Counter 3 = counter 1, counter 1 = counter 2, counter 2 = counter 3)
>>Set SAVED VALUE to loopstep + 1
>>Set COUNTER CHANGED to 1

Then repeat until the loop runs without changing the COUNTER CHANGED value to 1.

No stinking clue if that will work.

You could also perhaps use the high score object?

Edited by OMC

 

  		
  		

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
12th July, 2009 at 02:43:26 -

Does the swap with another object command in tgf/mmf work for instances? .. or is it just for seperate actives?
Maybe if someone figured out how to use it, they could make this bubble sort algorithm for use in the Klik universe.


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

nim



Registered
  17/05/2002
Points
  7234
12th July, 2009 at 02:45:37 -

It might be easier to load all of your counter values into an array (using the Dynamic Array object) and use its "Sort by Values" function.

 
//

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
12th July, 2009 at 02:47:15 -

Is it essential that you physically move the counters or can you just change their values so that they are in the correct order? It would be much simpler to create the counter and set its value than to reposition them.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th July, 2009 at 03:32:11 -

This is probably not the best way to do it, but it does work...
I made an example file here: http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/sorter.mfa

You MUST TICK "Sort" in the List object's properties.
You MUST UNTICK "1-Based Index" in the List object's properties.
This example would only support values up to 999, and only up to 999 objects, but can be easily modified to increase those limits. You could also use the string parser extension, and then it could handle any values you wanted.

● Start of sorting process...
→ List: Set Flag0 to ON
→ Start Loop "Add to List", NObjects("Object") times

● On Loop "Add to List"
● ID Number("Object") = LoopIndex("Add to List")
→ List: Add line "Right$("000"+Str$(Sortable Value( "Object" )), 3)+Right$("000"+Str$(ID Number( "Object" )), 3)"

● List: Flag0 is ON
→ List: Set Flag0 to OFF
→ Start Loop "Sort List", NObjects("Object") times

● On Loop "Sort List"
● ID Number("Object") = Val(Right$(List Line Text$( "List", LoopIndex("Sort List")), 3))
→ Set Rank("Object") to LoopIndex("Sort List")

Edited by Sketchy

 
n/a

erghhhhx



Registered
  15/11/2007
Points
  311

Mushroom
12th July, 2009 at 13:03:41 -

Hah, thanks for all the help guys. I tried out some combinations of your suggestions and I made it work.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click