Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Perlscript
➜ Would like a semi-complex (to my thinking) script...
Would like a semi-complex (to my thinking) script...
|
Posting of new messages is disabled at present.
Refresh page
Posted by
| Oberon
(4 posts) Bio
|
Date
| Mon 28 Jan 2002 02:08 AM (UTC) |
Message
| Well, I'm not asking for someone to just up and write this for me, but a few hints would be nice. Here's what it should do.
Command: prospect
If the MUD returns something with the word "gems" then:
mine gems
Otherwise:
read from a file to see where to move next, and move there
Check to see if vitality is 30 or below. If it is:
cast refresh, verify that it worked, if it didn't cast it again, repeat until it works.
If vitality is above 30:
prospect
and so it starts all over again. I can do most of this just fine, I've made simple triggers with reg. expressions that will see if I've found gems or not and if not, move on. What I'm having trouble with is that it'll only move in one direction. So it'll run to the end of this line of desert, but it just sits there at the end. (If you try prospecting where there's nothing it gives you a message like "There's nothing worth mining here." so it doesn't hit any triggers.) So... if someone could help me out with:
How to make a file that the script can read, line by line, to tell it where to go next from where it is now;
How to turn that file into a command that it gets when it hits the "where do we go next?" stage;
I think I can get the rest of it on my own.
Thanks in advance for your help! | Top |
|
Posted by
| Dubthach
(47 posts) Bio
|
Date
| Reply #1 on Mon 28 Jan 2002 02:51 PM (UTC) |
Message
| Reading a file is very easy in Perl.
# open "myfile.txt" from the same directory as the script is running
# refer to the file by its handle IN
open(IN, "myfile.txt") or die "Couldn't open input file.";
#Then you do a little perl magic with angled brackets.
while (<IN>)
{
# the $_ variable refers to the current line
}
# Then you close the file
close(IN);
In your case, I would probably shove the file into an array. Then just use foreach to loop through the array, running your program at each iteration.
| Top |
|
Posted by
| Nick Gammon
Australia (23,122 posts) Bio
Forum Administrator |
Date
| Reply #2 on Mon 28 Jan 2002 09:59 PM (UTC) |
Message
| For ideas, look at the post Auto Walker. It describes an auto-walker that automatically goes into different directions depending on what it sees.
This is similar to what you are trying to do. Yours is a bit more complex, because you want to react on what happens if you don't get the word 'gems', but to do this you would make a trigger that matches on everything (eg. '*') and then - if a flag is set - test the returned wildcard for the word 'gems'.
Alternatively, you could look for the key phrase 'There's nothing worth mining here' and then choose another direction. Perhaps a trigger that matched on the 'exits' line would help to know what directions are valid.
If you wanted to get fancy you could save in variables the room descriptions (names) of each room, and the directions you have already gone (the name could be the variable name, and the direction(s) the contents) so you don't walk in the same direction again.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,036 views.
Posting of new messages is disabled at present.
Refresh page
top