PDA

View Full Version : Using Variable Extraction with Time Verb



BigWorm
04-21-2004, 06:48 PM
I try my best to stay out of jail, but during Beta I played in the stocks a bit. Anyway, the debate about the stocks script and the way some people chose to solve it made me wonder. I decided to waste about three hours of my life and show a few different ways to do variable extraction with the Wizard. This script uses the time verb to figure out the current day of the week, month, time, etc. and will convert the Elanthian versions into English versions. Although sometimes the structure uses the time verb more times than are really required, this is a function of the structure of the counting section that allows it to be much more expandable.

Since I wrote the script in about three hours, I'm sure there are some bugs (I'm really not sure about how the Day of the Huntress [Friday] will work), but I got many of the other kinks worked out.

This script doesn't output the information in a very "pretty" way, but this is mostly due to the two variable nature of the Wizard. It's also right about useless, but it's more about the concepts than the function. Also, because of the way the script is written, it would be pretty easy to break it up to only get the minutes of the hour for instance.

I think Bob said that %c and %s are already used by the Stockade script, but I'm too lazy to look at the script and see if I could modify it to use a more flexible structure because I'm rarely in the stockades.

Anyway, here's the script. I'll probably play around with it some more and post some edits later.

Damn, the BBCode code format looks shitty. I'll post an attachment too that should look better.



# Find the current day, month, year, etc.

Start:
COUNTER SET 0
SAVE ""

FindWeekDay:
MATCH WeekDayRestday Today is Restday,
MATCH WeekDayVolnes Today is Volnes,
MATCH WeekDayTilamaires Today is Tilamaires,
MATCH WeekDayLeyan Today is Leyan,
MATCH WeekDayNiiman Today is Niiman,
MATCH WeekDayDayOfTheHuntress Today is the Day of the Huntress,
MATCH WeekDayFeastday Today is Feastday,
MATCH WeekDayError elven time standard.
PUT time
MATCHWAIT

WeekDayRestday:
SAVE Restday
GOTO FoundWeekDay

WeekDayVolnes:
SAVE Volnes
GOTO FoundWeekDay

WeekDayTilamaires:
SAVE Tilamaires
GOTO FoundWeekDay

WeekDayLeyan:
SAVE Leyan
GOTO FoundWeekDay

WeekDayNiiman:
SAVE Niiman
GOTO FoundWeekDay

WeekDayDayOfTheHuntress:
SAVE "Day of the Huntress"
SAVE Day_of_the_Huntress
GOTO FoundWeekDay

WeekDayFeastday:
SAVE Feastday
GOTO FoundWeekDay

WeekDayError:
SAVE "Error in FindWeekDay"
GOTO FatalError

FoundWeekDay:
ECHO * Day of the week: %s
GOTO ConvertWeekDay
#GOTO FindDayOfMonth

ConvertWeekDay:
GOTO ConvertWeekDay%s

ConvertWeekDayRestday:
SAVE Sunday
GOTO FoundConvertedWeekDay

ConvertWeekDayVolnes:
SAVE Monday
GOTO FoundConvertedWeekDay

ConvertWeekDayTilamaires:
SAVE Tuesday
GOTO FoundConvertedWeekDay

ConvertWeekDayLeyan:
SAVE Wednesday
GOTO FoundConvertedWeekDay

ConvertWeekDayNiiman:
SAVE Thursday
GOTO FoundConvertedWeekDay

ConvertWeekDayDay_of_the_Huntress:
SAVE Friday
GOTO FoundConvertedWeekDay

ConvertWeekDayFeastday:
SAVE Saturday
GOTO FoundConvertedWeekDay

FoundConvertedWeekDay:
ECHO * Weekday in English: %s
GOTO FindDayOfMonth

FindDayOfMonth:
COUNTER SET 0
WAIT
MATCH DayOfMonth1 day 1
MATCH DayOfMonth2 day 2
MATCH DayOfMonth3 day 3
MATCH DayOfMonth4 day 4
MATCH DayOfMonth5 day 5
MATCH DayOfMonth6 day 6
MATCH DayOfMonth7 day 7
MATCH DayOfMonth8 day 8
MATCH DayOfMonth9 day 9
MATCH DayOfMonth0 day 0
MATCH DayOfMonthError elven time standard.
PUT time
MATCHWAIT

DayOfMonth1:
COUNTER SET %c1
GOTO DayOfMonthHelper

DayOfMonth2:
COUNTER SET %c2
GOTO DayOfMonthHelper

DayOfMonth3:
COUNTER SET %c3
GOTO DayOfMonthHelper

DayOfMonth4:
COUNTER SET %c4
GOTO DayOfMonthHelper

DayOfMonth5:
COUNTER SET %c5
GOTO DayOfMonthHelper

DayOfMonth6:
COUNTER SET %c6
GOTO DayOfMonthHelper

DayOfMonth7:
COUNTER SET %c7
GOTO DayOfMonthHelper

DayOfMonth8:
COUNTER SET %c8
GOTO DayOfMonthHelper

DayOfMonth9:
COUNTER SET %c9
GOTO DayOfMonthHelper

DayOfMonth0:
COUNTER SET %c0
GOTO DayOfMonthHelper

DayOfMonthHelper:
WAIT
MATCH DayOfMonth1 day %c1
MATCH DayOfMonth2 day %c2
MATCH DayOfMonth3 day %c3
MATCH DayOfMonth4 day %c4
MATCH DayOfMonth5 day %c5
MATCH DayOfMonth6 day %c6
MATCH DayOfMonth7 day %c7
MATCH DayOfMonth8 day %c8
MATCH DayOfMonth9 day %c9
MATCH DayOfMonth0 day %c0
MATCH FoundDayOfMonth day %c
MATCH DayOfMonthError elven time standard.
PUT time
MATCHWAIT

DayOfMonthError:
SAVE "Error in FindDayOfMonth"
GOTO FatalError

FoundDayOfMonth:
ECHO * Day of the month: %c
GOTO FindMonth

FindMonth:
SAVE ""
WAIT
MATCH MonthLormesta of the month Lormesta in the year
MATCH MonthFashanos of the month Fashanos in the year
MATCH MonthCharlatos of the month Charlatos in the year
MATCH MonthOlaesta of the month Olaesta in the year
MATCH MonthIvastaen of the month Ivastaen in the year
MATCH MonthLumnea of the month Lumnea in the year
MATCH MonthKoaratos of the month Koaratos in the year
MATCH MonthPhoenatos of the month Phoenatos in the year
MATCH MonthImaerasta of the month Imaerasta in the year
MATCH MonthJastatos of the month Jastatos in the year
MATCH MonthEoantos of the month Eoantos in the year
MATCH MonthEorgaen of the month Eorgaen in the year
MATCH MonthError elven time standard.
PUT time
MATCHWAIT

MonthLormesta:
SAVE Lormesta
GOTO FoundMonth

MonthFashanos:
SAVE Fashanos
GOTO FoundMonth

MonthCharlatos:
SAVE Charlatos
GOTO FoundMonth

MonthOlaesta:
SAVE Olaesta
GOTO FoundMonth

MonthIvastaen:
SAVE Ivastaen
GOTO FoundMonth

MonthLumnea:
SAVE Lumnea
GOTO FoundMonth

MonthKoaratos:
SAVE Koaratos
GOTO FoundMonth

MonthPhoenatos:
SAVE Phoenatos
GOTO FoundMonth

MonthImaerasta:
SAVE Imaerasta
GOTO FoundMonth

MonthJastatos:
SAVE Jastatos
GOTO FoundMonth

MonthEoantos:
SAVE Eoantos
GOTO FoundMonth

MonthEorgaen:
SAVE Eorgaen
GOTO FoundMonth

MonthError:
SAVE "Error in FindMonth"
GOTO FatalError

FoundMonth:
ECHO * Month: %s
GOTO ConvertMonth

#GOTO FindYear

ConvertMonth:
GOTO ConvertMonth%s

ConvertMonthLormesta:
SAVE January
GOTO FoundConvertedMonth

ConvertMonthFashanos:
SAVE February
GOTO FoundConvertedMonth

ConvertMonthCharlatos:
SAVE March
GOTO FoundConvertedMonth

ConvertMonthOlaesta:
SAVE April
GOTO FoundConvertedMonth

ConvertMonthIvastaen:
SAVE May
GOTO FoundConvertedMonth

ConvertMonthLumnea:
SAVE June
GOTO FoundConvertedMonth

ConvertMonthKoaratos:
SAVE July
GOTO FoundConvertedMonth

ConvertMonthPhoenatos:
SAVE August
GOTO FoundConvertedMonth

ConvertMonthImaerasta:
SAVE September
GOTO FoundConvertedMonth

ConvertMonthJastatos:
SAVE October
GOTO FoundConvertedMonth

ConvertMonthEoantos:
SAVE November
GOTO FoundConvertedMonth

ConvertMonthEorgaen:
SAVE December
GOTO FoundConvertedMonth

FoundConvertedMonth:
ECHO * Month in English: %s
GOTO FindYear

# The FindYear section is only set up to recognize up to 2008.
# It would be very easy to expand to forever, but would add four
# more uses of the time verb. I didn't see it as neccesary for a
# script with little practical purpose
FindYear:
COUNTER SET 0
WAIT
MATCH Year5104 in the year 5104. It is
MATCH Year5105 in the year 5105. It is
MATCH Year5106 in the year 5106. It is
MATCH Year5107 in the year 5107. It is
MATCH Year5108 in the year 5108. It is
MATCH YearError elven time standard.
PUT time
MATCHWAIT

Year5104:
COUNTER SET 5104
GOTO FoundYear

Year5105:
COUNTER SET 5105
GOTO FoundYear

Year5106:
COUNTER SET 5106
GOTO FoundYear

Year5107:
COUNTER SET 5107
GOTO FoundYear

Year5108:
COUNTER SET 5108
GOTO FoundYear

YearError:
SAVE "Error in FindYear"
GOTO FatalError

FoundYear:
ECHO * Year: %c
GOTO ConvertYear
#GOTO FindTime

ConvertYear:
COUNTER SUBTRACT 3100
GOTO FoundConvertedYear

FoundConvertedYear:
ECHO * Year in English: %c
GOTO FindTime

FindTime:
SAVE ""
GOTO FindHour

FindHour:

#WAIT
MATCH Hour1 It is %s1
MATCH Hour2 It is %s2
MATCH Hour3 It is %s3
MATCH Hour4 It is %s4
MATCH Hour5 It is %s5
MATCH Hour6 It is %s6
MATCH Hour7 It is %s7
MATCH Hour8 It is %s8
MATCH Hour9 It is %s9
MATCH Hour0 It is %s0
MATCH FoundHour It is %s:
MATCH HourError elven time standard.
PUT time
MATCHWAIT

Hour1:
SAVE %s1
GOTO FindHour

Hour2:
SAVE %s2
GOTO FindHour

Hour3:
SAVE %s3
GOTO FindHour

Hour4:
SAVE %s4
GOTO FindHour

Hour5:
SAVE %s5
GOTO FindHour

Hour6:
SAVE %s6
GOTO FindHour

Hour7:
SAVE %s7
GOTO FindHour

Hour8:
SAVE %s8
GOTO FindHour

Hour9:
SAVE %s9
GOTO FindHour

Hour0:
SAVE %s0
GOTO FindHour

HourError:
SAVE "Error in FindHour"
GOTO FatalError

FoundHour:
COUNTER SET 0
GOTO FindMinute

FindMinute:
MATCH Minute1 It is %s:1
MATCH Minute2 It is %s:2
MATCH Minute3 It is %s:3
MATCH Minute4 It is %s:4
MATCH Minute5 It is %s:5
MATCH Minute6 It is %s:6
MATCH Minute7 It is %s:7
MATCH Minute8 It is %s:8
MATCH Minute9 It is %s:9
MATCH Minute0 It is %s:0
MATCH MinuteError elven time standard.
PUT time
MATCHWAIT

Minute1:
COUNTER SET %c1
GOTO MinuteHelper

Minute2:
COUNTER SET %c2
GOTO MinuteHelper

Minute3:
COUNTER SET %c3
GOTO MinuteHelper

Minute4:
COUNTER SET %c4
GOTO MinuteHelper

Minute5:
COUNTER SET %c5
GOTO MinuteHelper

Minute6:
COUNTER SET %c6
GOTO MinuteHelper

Minute7:
COUNTER SET %c7
GOTO MinuteHelper

Minute8:
COUNTER SET %c8
GOTO MinuteHelper

Minute9:
COUNTER SET %c9
GOTO MinuteHelper

Minute0:
COUNTER SET %c0
GOTO MinuteHelper

MinuteHelper:
WAIT
MATCH Minute1 It is %s:%c1
MATCH Minute2 It is %s:%c2
MATCH Minute3 It is %s:%c3
MATCH Minute4 It is %s:%c4
MATCH Minute5 It is %s:%c5
MATCH Minute6 It is %s:%c6
MATCH Minute7 It is %s:%c7
MATCH Minute8 It is %s:%c8
MATCH Minute9 It is %s:%c9
MATCH Minute0 It is %s:%c0
MATCH MinuteLeadingZero It is %s:0%c by the elven time standard.
MATCH FoundMinute It is %s:%c by the elven time standard.
MATCH MinuteError elven time standard.
PUT time
MATCHWAIT

MinuteError:
SAVE "Error in FindMinute"
GOTO FatalError

MinuteLeadingZero:
ECHO * Leading Zero in Minute
# ECHO * Because of the way the Wizard saves the counter variable,
# ECHO * it trims leading zeros off of the variable. The variable
# ECHO * extraction still works, but the representation won't look
# ECHO * as pretty without a lot more code. Actually, if seperate
# ECHO * variables are not needed for the hour and minute, it is
# ECHO * easiest to combine the two into %s, but I feel that keeping
# ECHO * the variables seperate is more useful
GOTO FoundTime # Comment out this line to make the time representation in the Wizard to look right
GOTO FoundTimeLeadingZero

FoundTimeLeadingZero:
SAVE %s:0%c
ECHO * Time: %s
GOTO Done

FoundMinute:
GOTO FoundTime

TimeError:
SAVE "Error in FindTime"
GOTO FatalError

FoundTime:
ECHO * Time: %s:%c
GOTO Done

LabelError:
ECHO * LabelError, most likely due to conversion of Day of the Huntress
ECHO * Will attempt to fix problem, but issue is known
SAVE Friday
GOTO FoundConvertedWeekDay

FatalError:
ECHO *
ECHO * Fatal Error Encountered:
ECHO * %s
ECHO *
EXIT

Done:
EXIT

Latrinsorm
04-21-2004, 06:55 PM
#GOTO FindDayOfMonth

What's that line for? (foundweekday label) Or this one in FoundYear:

#GOTO FindTime

TheEschaton
04-21-2004, 07:06 PM
The question is, can you append the %s variable?

For example, if %s is "Tilamaires", and you want it to be "Tilamaires, day 5 of Olaesta", can you use SAVE for that?

Like

SAVE %s + ", day 5 of Olaesta"?

That would be a useful question to know the answer to.

-TheE-

Latrinsorm
04-21-2004, 07:23 PM
The answer is yes you can, but not like that. You have to have the quotes go all the way to the left of the %s.

BigWorm
04-21-2004, 07:26 PM
#GOTO FindDayOfMonth

What's that line for? (foundweekday label) Or this one in FoundYear:

#GOTO FindTime

Those are from before I had it convert the Elanthian day into the English day. If you comment out GOTO ConvertMonth and uncomment GOTO FindYear, it will just give the Elanthian version.

BigWorm
04-21-2004, 07:27 PM
Yes, you most definately can, but the way it works it more simple than that.

SAVE "Day of the Huntress"
SAVE "%s, day 23 of Olaesta"
ECHO %s

And that reminds me of the script I made when I found that out. I was trying to figure out the best way to repeat two (or more) commands. I found a few ways to do it, each with a different benefit, but what I really want to do is make an option for pausing so many times and repeating a finite number of times, but I haven't got around to that yet.

# Script Name: rep
# This version was coded in order to get around the Wizard's
# limitation of only allowing access to 9 tokens when
# processing input from the script call at the command line.
# However, the method in this version was abandoned because
# the Wizard allows the use of quotes to combine tokens, and
# I felt it was more important to use the %s variable for
# another purpose (probably pausing, although %c might work
# for that too. And just as a note, the numbers after each
# SHIFT command don't do anything, they're just there to help
# me keep track of how many shifts have been performed.

If_1 GOTO xStart
ECHO *
ECHO * Example: .rep sweep partner ; stand
ECHO * Script By: BigWorm
ECHO *
EXIT

xStart:
COUNTER SET 1
xCheck1:
GOTO %1
xCheck2:
GOTO %2
xCheck3:
GOTO %3
xCheck4:
GOTO %4
xCheck5:
GOTO %5
xCheck6:
GOTO %6
xCheck7:
GOTO %7
xCheck8:
GOTO %8
xCheck9:
GOTO %9
xCheck10:
GOTO SimpleRepeat

LabelError:
COUNTER ADD 1
GOTO xCheck%c

IF_%c GOTO xCheck%c
GOTO xSimpleRepeat

;:
GOTO xBuild%c
#GOTO xCarriage%c

xSimpleRepeat:
PUT %0
WAIT
PUT %0
WAIT
GOTO xSimpleRepeat

xBuild1:
SHIFT 1
SAVE %0
GOTO xOutput

xBuild2:
SAVE "%1"
SHIFT 1
SHIFT 2
GOTO xOutput

xBuild3:
SAVE "%1 %2"
SHIFT 1
SHIFT 2
SHIFT 3
GOTO xOutput

xBuild4:
SAVE "%1 %2 %3"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
GOTO xOutput

xBuild5:
SAVE "%1 %2 %3 %4"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
SHIFT 5
GOTO xOutput

xBuild6:
SAVE "%1 %2 %3 %4 %5"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
SHIFT 5
SHIFT 6
GOTO xOutput

xBuild7:
SAVE "%1 %2 %3 %4 %5 %6"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
SHIFT 5
SHIFT 6
SHIFT 7
GOTO xOutput

xBuild8:
SAVE "%1 %2 %3 %4 %5 %6 %7"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
SHIFT 5
SHIFT 6
SHIFT 7
SHIFT 8
GOTO xOutput

xBuild9:
SAVE "%1 %2 %3 %4 %5 %6 %7 %8"
SHIFT 1
SHIFT 2
SHIFT 3
SHIFT 4
SHIFT 5
SHIFT 6
SHIFT 7
SHIFT 8
SHIFT 9
GOTO xOutput

xOutput:
PUT %s
#WAIT
PUT %0
WAIT
GOTO xOutput

Jonty
04-21-2004, 07:36 PM
Originally posted by TheEschaton
The question is, can you append the %s variable?

For example, if %s is "Tilamaires", and you want it to be "Tilamaires, day 5 of Olaesta", can you use SAVE for that?

Like

SAVE %s + ", day 5 of Olaesta"?

That would be a useful question to know the answer to.

-TheE-

The save command doesn't save the current value of the save variable past a white space.

Example:
save "my name is Jonty."

echo
echo %s
echo

save %s

echo
echo %s
echo

Results in:

.temp

My name is Jonty.


My


[Script finished!]

Jonty
04-21-2004, 07:37 PM
OK, you need quotation marks around the %s I see...

[Edited on 4-21-2004 by Jonty]