Jump to content


Photo

Quimp Data Structure


  • Please log in to reply
3 replies to this topic

#1 Quimp

Quimp

    Pretzel fanatic

  • New Member
  • 275 posts

Posted 03 March 2007 - 07:11 AM

Quimp Data Structure is a handy set of functions to sort 2D arrays alphabetically or numerically, in ascending or descending order. The extension works similarly to grid data structures, hence its name. The extension can be helpful to easily manage an high score table or user accounts.

The help file comes with two examples and is also available, temporarily, here: http://www.quimp.net...maker/help.html.


Download
http://www.quimp.net/downloads/qds.zip (approx. 6 kb).


Regards,
Quimp

Edited by Quimp, 03 March 2007 - 07:11 AM.

  • 0

#2 pcnerd

pcnerd

    GMC Member

  • New Member
  • 197 posts

Posted 03 March 2007 - 12:14 PM

cool. any way to create a row any number of times as the user says to, and then pick a random one of the last two of them and move them to the front?

Example:
user says to create it 5 times.
creates five rows.
pick one of the last two descending at random (but make sure it is not one in the middle or at the beginning of the quimp) and moves it to the front.

Edited by pcnerd, 03 March 2007 - 12:14 PM.

  • 0

#3 Quimp

Quimp

    Pretzel fanatic

  • New Member
  • 275 posts

Posted 03 March 2007 - 04:22 PM

What do you mean by "move them to the front"? Do you want to move the picked row in the first position in the sorted list, whatever values it has? If so, it's easy. You simply need to add a column called PRIORITY and give every rows a value of 0. Of course the row you picked will need to have a higher value. Sort everything in an order that will make the prioritized rows come first in the sorted list.

Example:
NAME = 0;
SOCKS_COLOR = 1;
PRIORITY = 2;

ds_quimp_create(3);
ds_quimp_asc(false);

var get, i, row;
do
 {
  get = get_integer("How many rows do you want to add?", 5);
 }
until (get > 0)

for (i=0; i<get; i+=1)
 {
  row = ds_quimp_add_row();
  ds_quimp_set(row, NAME, "Some name");
  ds_quimp_set(row, SOCKS_COLOR, round(random(255)));
  ds_quimp_set(row, PRIORITY, (i == get-1)); //make it (i == get-2) for the second last
 }

ds_quimp_order(0, PRIORITY);
ds_quimp_order(1, SOCKS_COLOR);
ds_quimp_order(2, NAME);

ds_quimp_sort();

for (i=0; i<=ds_quimp_rows(); i+=1)
 {
  show_message("Position " + string(i + 1) + "#Name: " + ds_quimp_get(i, NAME, true) + "#Socks color: " + string(ds_quimp_get(i, SOCKS_COLOR, true)));
 }

ds_quimp_destroy();

I hope that helps.
  • 0

#4 pcnerd

pcnerd

    GMC Member

  • New Member
  • 197 posts

Posted 04 March 2007 - 02:56 AM

Um... well... I got lost half way through. The simplest layout that I can think of to solve this problem is
//get number over three
//get values for each number from the user
//set the numbers to random positions
and then, when a different script is called,
//take the bottom two values and move them to the top
//chance one out of two move the second value (just moved up with the first) to before the first
//print on the screen

I came up with some code, but I am no good at quimps, so I don't know if this works or not:
ds_quimp_create(2);
do num = get_integer("Number over 3",3) until num > 3;
ds_quimp_asc(true);
for (i = 0; i < num; i += 1) {
  a = ds_quimp_add_row();
  ds_quimp_set(a,0,get_string("name:",""));
  ds_quimp_set(a,1,i + 2);
}
ds_quimp_order(0,1);
ds_quimp_order(1,0);
other script:
ds_quimp_set(ds_quimp_rows(),2,1);
ds_quimp_order(0,1);
ds_quimp_order(1,0);
ds_quimp_set(ds_quimp_rows(),2,0);
ds_quimp_order(0,1);
ds_quimp_order(1,0);
for (i = 0; i < ds_quimp_rows(); i += 1) {
  ds_quimp_set(i,2,ds_quimp_get(i,2,true) + 2);
}
ds_quimp_order(0,1);
ds_quimp_order(1,0);
i = choose(1,2);
if i = 1 {
  ds_quimp_set(1,2,ds_quimp_get(2,2,true));
  ds_quimp_set(2,2,ds_quimp_get(2,2,true) - 1);
}
And I also don't know how to record the values.

Edited by pcnerd, 04 March 2007 - 03:36 AM.

  • 0