Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Switches and random

 [1/3] from: izkata::aol::com at: 17-Feb-2002 14:24


I am making a welcome message type of script, and am wondering why this doesn't work: (Yes, I have to use switches, or something similar for my idea to work) word1: "" word2: "" word3: "" Word1: random/only ['I 'My 'Your] switch Word1 [ 'I [ Word2: random/only ['like 'hate] switch Word2 [ 'like [word3: random/only ['you]] 'hate [word3: random/only ['viruses]] ] ] 'My [Word2: random/only ["name is Tenryo"]] 'Your [word2: random/only ['boring]] ] Sentence: to-string append "" rejoin [Word1 " " word2 " " word3 "."] flash Sentence Daniel S.

 [2/3] from: joel:neely:fedex at: 17-Feb-2002 16:48


Hi, Daniel, [Izkata--aol--com] wrote:
> I am making a welcome message type of script, > ... Yes, I have to use switches, or something similar... >
Here's a version that doesn't require switch, lets you change the range of phrases by changing data, and lets you use predefined phrases at various places in the phrase tree. HTH! -jn- 8<-------------------------------------------------------- randphrase: make object! [ languages: [ "favorite language is" [ "REBOL"] [ "predicate calculus"] ] desserts: [ "favorite dessert is" [ "chocolate cake"] [ "strawberry cheesecake"] [ "espresso"] ] phrasetree: [ [ "I" [ "like" [ "you"] [ "coffee"] ] [ "hate" [ "viruses"] [ "bugs"] ] ] [ "My" languages desserts ] [ "Your" languages [ "favorite color is" [ "periwinkle"] [ "mauve"] ] ] ] run: func [/local sentence gap branch] [ sentence: copy "" gap: "" branch: phrasetree while [0 < length? branch] [ branch: reduce random/only branch sentence: rejoin [sentence gap branch/1] gap: " " branch: next branch ] join sentence "." ] ] 8<-------------------------------------------------------- which does this: 8<--------------------------------------------------------
>> randphrase/run
== "My favorite language is predicate calculus."
>> randphrase/run
== "I like you."
>> randphrase/run
== "I hate bugs."
>> randphrase/run
== "I like coffee."
>> randphrase/run
== "I hate bugs."
>> randphrase/run
== "Your favorite color is mauve."
>> randphrase/run
== "Your favorite language is REBOL." 8<-------------------------------------------------------- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;

 [3/3] from: izkata:aol at: 18-Feb-2002 21:19


I'll have to fool aroung with it a bit, but I think it will work.