On 12-May-02, Ed Dana wrote:

> In an effort to understand this new (and very interesting) language,
> I decided to try something simple; I created a simple guessing game
> where the computer picks a number between 1 and 100.

> Simply yes? Yea, right! :)

> For whatevcr reason: newbie, stupidity, or that my computer just
> plain hates me, I can't get the silly thing to work.

> Here is the script:
> REBOL [
>    Title:    "Guess a number between 1 and 100"
>    Date:     05/11/2002
>    Version:  0
>    Author:   "Ed Dana"
>    Purpose:  "An excersize in REBOLion."
>    Comment:  "Just goofing off."
>    Category: [game]
> ]

> pick: random/seed 100.0

> guess: ask {What is your guess? }

> while [pick <> guess] [
>  if [pick < guess] [ print "To low"  ]
>  if [pick > guess] [ print "To high" ]
>  guess: input 
> ]

> print pick

> And the results I get:
>>> do %guess.r
> What is your guess? ** Script Error: trim expected series argument
> of type: series port
> ** Where: ask
> ** Near: trim either hide [input/hide] [input]

> What is it talking about? I haven't a clue.

> I've even tried using Guess: Input and it defines Guess as 1.

> Any advice is appreciated, including types on suicide so that I may
> hide my shame from such a simple newbie mistake. :)

Hi Ed,

A few REBOL specific mistakes there...

    pick: random/seed 100.0

'pick shouldn't be used there, as it's a common REBOL word and I think
may have been the cause of your error message.  Anyway, changing it
to 'target prevented the error happening for me. ie...

    target: random/seed 100.0

(Adding 'protect-system to your user.r script will prevent this kind
of problem by not allowing you to over-write the default REBOL
words.)

Another problem is with the 'ifs...

    if [target < guess] [ print "To low"  ]

The "target < guess" shouldn't be in a block there, as 'if doesn't
evaluate the block like 'while does.  So, this is the correct syntax
for 'if...

    if target < guess [ print "To low"  ]

but it still won't work in your case as you're comparing a number
(target) with a string (guess).  So, to fix that use...

    if target < to-integer guess [ print "To low"  ]

Which should almost get your script working for you.  (I say almost as
I'm leaving what you really should be ashamed of for you to find out
for yourself;)

HTH.

-- 
Carl Read

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to