Tuesday 26 May 2009

GAAAAAHHHHHH!!!!!!

I mean it, GAAAAHHHHH!!!!!!

Remeber me writing, a little while ago, that I was trying to write an Apple script, to generate a Tunnels and Trolls character?

Well …

GAAAAHHHHH!!!!!

Or to put it more rational, I think I’m getting closer.

While I’ve not managed to figure out how to send the various numbers to a pre-prepared character sheet, I have managed to reconfigure the script so that it can alter the figures, so that it can modify the numbers, depending on which race you chose.

But here’s what I’ve got so far.

display dialog "Would you like to generate a T & T character?" buttons {"No", "Yes"} default button 2

if the button returned of the result is "No" then

say "Ok, that’s cool." using "Vicki"

else

set numberslist to {3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 18}

set Strength1 to some item of numberslist

set Intelligence1 to some item of numberslist

set Luck1 to some item of numberslist

set Constitution1 to some item of numberslist

set Dexterity1 to some item of numberslist

set Charisma1 to some item of numberslist

end if


display dialog "Would you like to be Human, Elf, or Dwarf?" default answer "Your Character’s Race"

set playerRace to the text returned of result



if playerRace is "Human" or "human" then set Strength2 to Strength1

if playerRace is "Human" or "human" then set Intelligence2 to Intelligence1

if playerRace is "Human" or "human" then set Luck2 to Luck1

if playerRace is "Human" or "human" then set Constitution2 to Constitution1

if playerRace is "Human" or "human" then set Dexterity2 to Dexterity1

if playerRace is "Human" or "human" then set Charisma2 to Charisma1

if playerRace is "Elf" or "elf" then set Strength2 to Strength1

if playerRace is "Elf" or "elf" then set Intelligence2 to (Intelligence1 * (3 / 2))

if playerRace is "Elf" or "elf" then set Luck2 to Luck1

if playerRace is "Elf" or "elf" then set Constitution2 to (Constitution1 * (2 / 3))

if playerRace is "Elf" or "elf" then set Dexterity2 to (Dexterity1 * (3 / 2))

if playerRace is "Elf" or "elf" then set Charisma2 to (Charisma1 * 2)

if playerRace is "Dwarf" or "dwarf" then set Strength2 to (Strength1 * 2)

if playerRace is "Dwarf" or "dwarf" then set Intelligence2 to Intelligence1

if playerRace is "Dwarf" or "dwarf" then set Luck2 to Luck1

if playerRace is "Dwarf" or "dwarf" then set Constitution2 to (Constitution1 * 2)

if playerRace is "Dwarf" or "dwarf" then set Dexterity2 to Dexterity1

if playerRace is "Dwarf" or "dwarf" then set Charisma2 to (Charisma1 * (2 / 3))


set w to 0

set x to 0

set y to 0

set z to 0

if Strength2 is greater than 12 then set w to Strength2 - 12

if Strength2 is less than 9 then set w to 9 - Strength2

if Intelligence2 is greater than 12 then set x to Intelligence2 - 12

if Intelligence2 is less than 9 then set x to 9 - Intelligence2

if Luck2 is greater than 12 then set y to Luck2 - 12

if Luck2 is less than 9 then set y to 9 - Luck2

if Dexterity2 is greater than 12 then set z to Dexterity2 - 12

if Dexterity2 is less than 9 then set z to 9 - Dexterity2


set CombatAdds to w + x + y + z


say "Your Strength is" using "Vicki"

say Strength2 using "Vicki"

say "Your Inteligence is" using "Vicki"

say Intelligence2 using "Vicki"

say "Your Luck is" using "Vicki"

say Luck2 using "Vicki"

say "Your Constitution is" using "Vicki"

say Constitution2 using "Vicki"

say "Your Dexterity is" using "Vicki"

say Dexterity2 using "Vicki"

say "Your Charisma is" using "Vicki"

say Charisma2 using "Vicki"


if CombatAdds is greater than 0 then say "You have a combat bonus of plus" using "Vicki"

if CombatAdds is greater than 0 then say CombatAdds using "Vicki"


if CombatAdds is less than 0 then say "You have a combat modifier of minus" using "Vicki"

if CombatAdds is less than 0 then say CombatAdds


if CombatAdds is equal to 0 then say "You do not have a combat modifier" using "Vicki"



set Gold to (some item of numberslist) * 10


say "You have " using "Vicki"

say Gold using "Vicki"

say " gold pieces" using "Vicki"


say "Please enjoy your character’s adventures" using "Vicki"


Which works fine, as it stands.

I do know I’ll have to work on using the “round” command to turn those values; obviously, having a Strength of 10.6 recurring, would be just plain silly!

And — if all else fails — I know I can insert the following bit of code to print out a character sheet.

tell application "Preview"

activate

open the file "Hard Drive:Users:Home Folder:Desktop:Tunnels and Trolls scripts:Sheet.pdf"

print the file "Hard Drive:Users:Home Folder:Desktop:Tunnels and Trolls scripts:Sheet.pdf"

tell application "Preview"

quit

end tell

end tell


I’ll update you all later!

No comments: