Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-11-2010, 07:33 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
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..
Reply With Quote
  #2  
Old 07-11-2010, 10:23 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
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).
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #3  
Old 07-11-2010, 04:37 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
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.arrtemp.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.arrtemp.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.arrtemp.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(arrsel) {
  
temp.str "";
  
  for (
temp.= -1temp.=< 1temp.++) {
    
temp.str @= temp.arr[(temp.sel temp.i) % temp.arr.size()] @ " ";
  }
  
  echo(
temp.str);

__________________
Reply With Quote
  #4  
Old 07-11-2010, 10:02 PM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
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?
Reply With Quote
  #5  
Old 07-11-2010, 10:03 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by DeCeaseD View Post
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?
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
Reply With Quote
  #6  
Old 07-11-2010, 10:04 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Maybe you should use showimg or showtext or whatever the hell and come up with a reasonable way to calculate coordinates!
Reply With Quote
  #7  
Old 07-11-2010, 10:08 PM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Quote:
Originally Posted by Loriel View Post
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.
Reply With Quote
  #8  
Old 07-11-2010, 10:31 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by DeCeaseD View Post
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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:11 AM.


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