|
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: Mon Jul 23, 2007 2:13 am
Randomize and movement |
Okay, looking at writing a little trigger or possibly it would be an aliases but want it to go something like this:
DO
Random i 1-4
if i = 1 then north
if i = 2 then east
if i = 3 then west
if i = 4 then south
wait 3
LOOP
Okay, so that is cheep basic command code :P Obviously it would not look like that in zscript. I just want to make something so I can have a char walk around randomly. I'm obviously going to add a lot more to it but I don't know if there is a DO...LOOP function or a randomize function and if so, I haven’t found it in the help files. Any ideas? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jul 23, 2007 2:31 am |
Couple of ways of doing it. Easiest, allowing for a variable list:
#exec %item(@list,%random(1,%numitems(@list))
closest to what you suggested:
#case %random {north} {east} {west} {south}
If you're using the mapper you could use %roomexit to have it only try to move in directions that exist. |
|
|
|
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: Mon Jul 23, 2007 3:05 am |
Heh, I don't use the automapper but honestly I don't understand the code there. :P
So, how do I do it? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jul 23, 2007 3:46 am |
Well, if you just want to choose a random direction, the #case command takes an expression as its first argument (in this case, a random number). Whatever number comes out of the expression, it chooses that number-th command to execute. If the number were 2, it'd choose the 2nd command and so on. Since it's a random number, it'll choose a random command.
The %item example takes a list and uses the %item function to extract an item from it. The number of the item is chosen at random, between 1 and the number of items in the list. Look the functions and commands up in the help files. |
|
|
|
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: Mon Jul 23, 2007 4:10 am |
okay, so how about the do... loop part?
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jul 23, 2007 4:17 am |
So you just want it to repeat the random movement every three seconds?
#alarm "RandomMove" {*3} {#case %random {north} {east} {west} {south}}
Then you can enable and disable it with #t+ and #t- too. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Mon Jul 23, 2007 12:46 pm |
When looking at other programming languages it is a good thing to remember that Do is actually Do #Until.
I would suggest using an alarm the way Fang is though. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: Tue Jul 24, 2007 4:00 am |
perfect. thanks. :)
- Winslow |
|
|
|
|
|