Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Best way to "slide" an array? (https://forums.graalonline.com/forums/showthread.php?t=134259791)

DeCeaseD 07-11-2010 07:33 AM

Best way to "slide" an array?
 
Okay so.. I'm trying to display a list of categories, I have these said categories listed in an array. Basically what I want from this is display 3 of the 6 categories in a vertical line, than as I press the left or right key, I would like to cycle through these categories. I have done this.. but it isn't the desired effect that I want. I want these categories to "slide" left and right when you scroll through them.. Basically say I have, "Test 1", "Test 2", "Test 3" and "Test 4", 1 through 3 are displayed, 2 being the selected category, I than press the left key, Test 2 would slide to where Test 1 is display, Test 3 sliding to where Test 2 is, and than Test 4 coming in from the side going to where Test 3 was, so on and so forth. Anyone mind giving me some tips on what would be the best way to do this.. ? I can't think of any way to do it.. :confused:

Switch 07-11-2010 10:23 AM

When sliding down (everything's shifted up), find the farthest category on the bottom's (that's visible) position in the array. Slide everything up (hide the top-most visible), and get the next category. If you're at the end of the array, just get the first entry. Opposite applies for sliding up (shifted down).

salesman 07-11-2010 04:37 PM

I usually just keep track of the index of the currently selected item (the one in the middle), and then increase or decrease that index whenever the user "slides" the list right or left and mod by the size of the array.

For example,
PHP Code:

function onCreated() {
  
temp.arr = {"a", "b", "c", "d", "e", "f"};
  
temp.sel = 0; // The index of the item in the middle

  
this.printDisplay(temp.arr, temp.sel); // echoes "f a b"

  /* Now, slide to the left */
  
temp.sel = (temp.sel + 1) % temp.arr.size(); // is now 1, so "b" is the middle item
  
  
this.printDisplay(temp.arr, temp.sel); // echoes "a b c"
  
  /*  Now, slide to the right twice 
      Assuming you'd always slide one at a time 
      whenever the user presses a key */
      
  
temp.sel = (temp.sel - 1) % temp.arr.size(); // is now 0, "a" is in the middle again
  
temp.sel = (temp.sel - 1) % temp.arr.size(); // is now 5, "f" is in the middle
  
  
this.printDisplay(temp.arr, temp.sel); // echoes "e f a"
}

/* This is generally how I would show what's on the 
   left and right of the selected item. You can do your image
   drawing or whatever here.
    
   If you have a special case for the one in the middle, such
   as having it highlighted or something, just check 
     if (temp.i == 0) { <Stuff for the middle item here> }
*/

function printDisplay(arr, sel) {
  
temp.str = "";
  
  for (
temp.i = -1; temp.i =< 1; temp.i ++) {
    
temp.str @= temp.arr[(temp.sel + temp.i) % temp.arr.size()] @ " ";
  }
  
  echo(
temp.str);
} 


DeCeaseD 07-11-2010 10:02 PM

That works and all.. but it's not exactly what I meant by slide.. I already have done what you're doing, but when I say slide, I mean I want the variables to actually have a visible slide.. meaning they MOVE from point a to point b. If you know what I mean? :confused:

Loriel 07-11-2010 10:03 PM

Quote:

Originally Posted by DeCeaseD (Post 1587070)
That works and all.. but it's not exactly what I meant by slide.. I already have done what you're doing, but when I say slide, I mean I want the variables to actually have a visible slide.. meaning they MOVE from point a to point b. If you know what I mean? :confused:

variables do not move

they do not have a position

they also do not have an appearance so you could not even see them move if they did

what are you even talking about

Loriel 07-11-2010 10:04 PM

Maybe you should use showimg or showtext or whatever the hell and come up with a reasonable way to calculate coordinates!

DeCeaseD 07-11-2010 10:08 PM

Quote:

Originally Posted by Loriel (Post 1587072)
Maybe you should use showimg or showtext or whatever the hell and come up with a reasonable way to calculate coordinates!

Well that's the issue.. I can't think of a way to calculate the coordinates for each one of the displayed texts, especially if I'm using a for loop to display said array.

Loriel 07-11-2010 10:31 PM

Quote:

Originally Posted by DeCeaseD (Post 1587073)
Well that's the issue.. I can't think of a way to calculate the coordinates for each one of the displayed texts, especially if I'm using a for loop to display said array.

Figure out how space you want to dedicate to the entire array, then figure out how to subdivide it into even chunks for each the elements, then for sliding figure out how to get from one of the chunks to the other in many small steps?


All times are GMT +2. The time now is 10:57 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.