PDA

View Full Version : Getting jail answers



stormtov
08-23-2008, 06:42 PM
I was in jail today so went to start the script to answer the questions and i realized how much hassle it was even doing this so thought id try it with rich. Then i realized i only know how to extract one word at a time. Don't really want to spam info 4 or so times just to get the info i need. so what would be the best way to go about doing this?

The info i need would be profession, name, race, gender, day, month, year and the hour.

Any info on how to extract all this information with out having to keep repeating the info and time command to get them one at a time would be appreciated.

Imperarx
08-24-2008, 02:37 AM
I'm not sure what kind of format the time is looking for, so you'd have to tell me what time it's asking for (game time, game days, etc?) but for the others lich has built in variables.

Char.name, Char.prof, Char.race, Char.gender will return that information for your character.

So something like fput "answer #{Char.race}" would respond with your race. Try messing around with that, and give me some idea of what it's looking for when it asks you about day and such (real day, game named day?)

stormtov
08-24-2008, 10:09 AM
ahh thanks for the info on the Char.xxx settings they could come in handy. This is where the rest of the info would need to be extracted from:

>time
Today is Restday, day 24 of the month Phoenatos in the year 5108. It is 09:49 by the elven time standard. It is currently mid morning.

Thinking about now it shouldn't be hard to put that in an array and pick out the corresponding part i need for the question. The thing i can foresee having problems with is with the time. In this case "09:49", i wouldn't know how to go about splitting the hour from the minutes.

I know the char.xxx part does this for me but i still have one question. If i was to go about extracting name, race and profession from this:

Name: Bob Race: Dark Elf Profession: Sorcerer (shown as: Doomsayer)

If i read that into an array the position of my profession would change depending on race(eg. dark elf or giant). Is there a way to account for this?

stormtov
08-24-2008, 05:39 PM
Ok here is my script so far, all i'm doing as checking i can get the variables i want:
=============
echo "your name is #{Char.name}, profession is #{Char.prof} and gender is #{Char.gender}"
put "time"
time = waitfor ("Today is").split
day = time[2]
month = time[8]
year = time[12]
hour = time[15]
echo "Day is #{day}, month is #{month}, year is #{year} and hour is #{hour}"
============
And this is the output:
============
[jail: your name is Dalzashel, profession is Sorcerer and gender is Male]
[jail]>time
Today is Restday, day 24 of the month Phoenatos in the year 5108. It is 17:36 by the elven time standard. It is currently late afternoon.
J>
[jail: Day is Restday,, month is Phoenatos, year is 5108. and hour is 17:36]
======
Just two problems. on the day im getting an extra "," and for the hour all i want is the 17 bit not the ":36". How would i trim off the bits i don't want?

stormtov
08-24-2008, 06:34 PM
Ok im getting better at this:

=====
echo "your name is #{Char.name}, profession is #{Char.prof} and gender is #{Char.gender}"
put "time"
time = waitfor ("Today is").split
day = time[2].split(",")
hour = time[15].scan(/../)
echo "Day is #{day[0]}, month is #{time[8]}, year is #{time[12].split(".")} and hour is #{hour[0]}"
====
And this outputs:

[jail: your name is Dalzashel, profession is Sorcerer and gender is Male]
[jail]>time
>
Today is Restday, day 24 of the month Phoenatos in the year 5108. It is 18:31 by the elven time standard. It is currently evening twilight.
>
[jail: Day is Restday, month is Phoenatos, year is 5108 and hour is 18]
====
Which is all the info i need in the correct format, but the point of this was to run a stormfront script that i was too lazy to convert to lich. So how do i start a SF script with my variables from the script above?

Imperarx
08-25-2008, 11:42 AM
Hey,

Looks like you parsed it down to what you want. Just so you know for future reference, lich has a function called matchfind that pulls words out of strings. It would work something like this.

items = matchfind "Today is ?, day ? of the month ? in the year ?. It is ?:? by the elven time standard."

All of the ? would be assigned into the array items, so this input

Today is Volnes, day 25 of the month Phoenatos in the year 5108. It is 11:34 by the elven time standard. It is currently mid morning.

would give
item[0]=Volnes
item[1]=25
item[2]=Phoenatos
item[3]=5108
item[4]=11
item[5]=34

As for your question about starting the stormfront script, make sure a copy of the script is in your lich script's directory, and then call it as follows

start_wizard_script "script name", [ "command line variable(s)", "etc" ]

Make sure you enclose the command line variables in brackets (they have to be passed as an array). So yours would look like

start_wizard_script "test", [ "#{day[0]", "#{time[8]}","#{time[12].split(".")}", "#{hour[0]}" ].

I haven't really used this much, so I don't know if you need to do your parsing ahead of time and store them in variables. Otherwise, you may have some trouble with the quotes necessary to do some of your splits. Usually I use matchfind to pull out sub-strings, and then it's easy to just grab the different elements.

Also, you may find some stormfront and wizard scripts don't work quite right in lich. I've never figured out the cause of this, but you may want to consider rewriting it, since it couldn't be too much harder now that you've figured out how to get the info extracted.


One last note. The lich api is at http://lichproject.sourceforge.net/api.xml and is full of all sorts of neat things that lich can do. It's a good read if you plan to make more scripts in lich.

BigWorm
08-25-2008, 01:37 PM
I would use a regex to parse it instead of spliting:


put "time"
$date_output = waitfor "^Today is"

if ( $date_output =~ /^Today is (\w+), day (\d+) of the month (\w+) in the year (\d+)\. It is (\d+):(\d+) by the elven time sta
ndard\./ )
{
$weekday = $1;
$day = $2;
$month = $3;
$year = $4;
$hour = $5;
$minute = $6;
echo "Day is #{day}, month is #{month}, year is #{year} and hour is #{hour}.";
}
else
{
print "Error parsing date.\n";

}

Imperarx
08-25-2008, 03:05 PM
I would use a regex to parse it instead of spliting:


put "time"
$date_output = waitfor "^Today is"

if ( $date_output =~ /^Today is (\w+), day (\d+) of the month (\w+) in the year (\d+)\. It is (\d+):(\d+) by the elven time sta
ndard\./ )
{
$weekday = $1;
$day = $2;
$month = $3;
$year = $4;
$hour = $5;
$minute = $6;
echo "Day is #{day}, month is #{month}, year is #{year} and hour is #{hour}.";
}
else
{
print "Error parsing date.\n";

}

As a note, only put $ in front of the variables if you want them accessible to other scripts. Otherwise, you're better off using variables that are local to your script rather than global. You'd be surprised how many people can't figure out their problems when they've made all global variables...

But this is a good example of the flexibility of lich. Because it's basically pure ruby, there will be a dozen ways to solve any problem, and you can use the one that's most comfortable to you.

BigWorm
08-25-2008, 03:20 PM
As a note, only put $ in front of the variables if you want them accessible to other scripts. Otherwise, you're better off using variables that are local to your script rather than global. You'd be surprised how many people can't figure out their problems when they've made all global variables...

But this is a good example of the flexibility of lich. Because it's basically pure ruby, there will be a dozen ways to solve any problem, and you can use the one that's most comfortable to you.

Sorry, good point. I tested that in perl since I don't have ruby here at work and perl vars require the $ sigil.

stormtov
08-25-2008, 06:01 PM
Ahh, thanks a lot to both of you. I did try something similar to matchfind to start with but misremembered and was using matchfindword. As for the regex option i have seen people using it in their scripts and have never been able to understand it enough to replicate it. Guess i should go look it up on the internet some where.

Took a surprisingly long time for that short script but i've learnt new stuff which is always good.

Thanks again for the input.