Re: TIB: Domain error


[Prev][Next][Index][Thread]

Re: TIB: Domain error




browningn@usa.net wrote:
> 
> I am working on a game. I am trying to get characters to randomly scroll down the screen. This should work but i get a domain error everytime i run it. Can any one see any problems in my code?
> 
> 8/->/x
> Lbl B
> IF x==8:Goto A
> (x+1)/->/x
> Outpt(x,y,"x")  <- i get the error right here
> Outpt(x-1,y," ")
> Goto B
> Lbl C
> (rand*20)/->/y
> If y>7 and y<21
> Then:Goto B
> Else:Goto C

Goto A? Where is that? I assume it might be C you mean...

OK.
Rand*20 will yield a number _between_ 0 and 20, you want one between 7
and 21. To do this, simply call (rand*14)+7.
Now, rand rarely returns an integer, which is what causes your domain
error. You call your output function with a decimal value (I don't have
my man with me hbut I'm pretty certain you can only call it with integer
values (?))
Use the Int( command to round your value down.
If you call Int(rand*14)+7 your results will be in this domain:
{7,8,...,19,20}. To change the domain's size, increase or decrease your
rand multiplier accordingly. To change the domains maximum/minimum value
(yup, you guessed it ;) change the integer you add in the end.

HTH.

-- 
          Rene Kragh Pedersen
------------------------------------------------------------------
Apparently my clothes are defective.
 - Dilbert.


References: