Sample Scripts
English spoken here!
OpenXION is the English-like programming language based on Apple's HyperTalk.
No Installation!
Just download, unzip, & run!
This are will expanded in the coming weeks. In the meantime, here are some of the sample scripts included with the full installation of OpenXION.
The Obligatory First Script
We must pay homage to the programming gods with our first script:
put "Hello world, from OpenXION!"
Lyrics to "99 bottle of bear on the wall"
on bottles start
repeat with x = start down to 1
if x = 1 then
put "1 bottle of beer on the wall,"
put "1 bottle of beer."
put "Take one down, pass it around,"
put "No more bottles of beer on the wall."
else
put x && "bottles of beer on the wall,"
put x && "bottles of beer."
put "Take one down, pass it around,"
if x-1 = 1 then
put "1 bottle of beer on the wall."
else
put (x-1) && "bottles of beer on the wall."
end if
put empty
end if
end repeat
end bottles
bottles 99
In the above example, the && symbol is used to concatenate two strings with a space in between.
The Age Game
ask "Pick the number of days a week that you would like to go out:"
put it into daysGoOut
put daysGoOut * 2 into daysGoOutA
put daysGoOutA + 5 into daysGoOutB
put daysGoOutB * 50 into daysGoOutC
answer "Have you had your birthday this year?" with "Yes" or "No"
if it is "Yes" then
put daysGoOutC + 1748 into daysGoOutD
else if it is "No" then
put daysGoOutC + 1747 into daysGoOutD
else
answer "Sorry, answer was invalid"
exit to interpreter
end if
ask "What is the four digit year that you were born?"
put it into birthYr
put daysGoOutD - birthYr into daysGoOutE
put "You want to go out:" && char 1 of daysGoOutE && ":times a week"
put "You are (or were):" && char 2 to 3 of daysGoOutE && ": years old (in 1998)"
--1 First of all, pick the number of days a week that you would like to go out.
--2 Multiply this number by 2.
--3 Add 5.
--4 Multiply it by 50
--5 If you have already had your birthday this year, add 1748. If you haven't, add 1747.
--6 Last step: Subtract the four digit year that you were born.
--RESULTS:
--You should now have a three digit number:
--The first digit of this was your original number (i.e. how many times to go out each week).
--The second two digits are your age!!! It really works.
--This is the only year (1998) it will ever work.
Factor
function factor theNumber
put empty into theFactors
repeat with theDivisor = 2 to the sqrt of theNumber
repeat while theNumber mod theDivisor is zero
put theDivisor & "*" after theFactors
divide theNumber by theDivisor
end repeat
if theNumber is one then exit repeat
end repeat
if theNumber is not one
then put theNumber after theFactors
else delete last char of theFactors
return theFactors
end factor
repeat
ask "Number to factor:"
if it is empty or the result is "Cancel" then exit repeat
else put factor(it)
end repeat
Primes
function isprime n
if n < 2 then return false
repeat with x = 2 to the sqrt of n
if n mod x == 0 then return false
end repeat
return true
end isprime
on primes cnt
repeat with x = 0 to cnt
if isprime(x) then
put x
end if
end repeat
end primes
ask "List primes up to:" with "50"
if it is not empty and the result is not "Cancel" then primes it
More sample scripts available here.