|
Berill Newbie
Joined: 29 May 2003 Posts: 6
|
Posted: Mon Jun 02, 2003 7:58 pm
Stringlist help |
I am trying to write a script which would move my character back and forth in an area. The directions are kept in a list like this:
#var directions {n|nw|e|ne|sw|w|se|s}
I wanted to set up an alias that would keep track of where I am in the list and when I input it, move me in the next direction. Everything that I have tried hasn't worked, so any help would be appreciated.
Thanks!
D |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Jun 02, 2003 10:40 pm |
#VAR Pointer 0
#AL GoNext {%item( @directions, (@Pointer8) + 1);#ADD Pointer 1}
LightBulb
Advanced Member |
|
|
|
Berill Newbie
Joined: 29 May 2003 Posts: 6
|
Posted: Tue Jun 03, 2003 7:32 am |
Thanks for the reply, but for some reason this isn't working for me... and since I don't even understand parts of it, I don't know what could be wrong. When I enter that, with the variable directions exactly like above, it doesn't display a thing.
What does the (Pointer8)+1) do? Wouldn't it be the same to just use @pointer there and then reset it when it hits %numitems( @directions)? Though thats not working either...
Thanks for any help
D |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Jun 03, 2003 11:45 am |
Yes, it is the same, plus it would adapt to changes in the size of the list. Not to say that LightBulb's solution can't be made to automatically use the list's size, but if you understand the other one better, then use it. Since you didn't provide what you tried, we can't tell you what's wrong with it. However, something like this should work:
#VAR pointer 1
#ALIAS GoNext {#EXEC %item(@directions, @pointer);#ADD pointer 1;#IF (@pointer > %numitems(@directions)) {#VAR pointer 1}}
The pointer will automatically go back to 1 when you reach the end of the list so the directions in the list should either end at the starting point, or you need to watch out for this.
Note: By the way, what (@Pointer8) + 1 does is to find the remainder of dividing the value of @Pointer by 8 and add one to it. So for every multiple of 8 this evaluates to 1 and to the corresponding list positions for the next 7 numbers.
Kjata |
|
|
|
|
|