Jump to content



0

Two questions: DIM and RAND


4 replies to this topic

#1 yuppicide OFFLINE  

yuppicide

    I am the Black Knight. Give me your money!

  • 6,933 posts
  • Location:New Jersey

Posted Wed Jul 30, 2008 9:18 PM

First, DIM:

I don't really need things like

 DIM backframe=a

Does it take up more room or the same if I add that dim and do backframe=backframe+1 as opposed to just doing a=a+1?

Second, RAND:

I read up on doing something like

 a=rand

What I need is a random number between 4 and 27. How exactly do I? Is something like this possible?

loop
 a = rand
 if a>27 and a<4 then goto loop
 if a<27 and a>4 then goto loop2

Will that slow things down too much because it might keep picking numbers out of my range randomizing over and over and over?

Going to bed now. Thanks again. I've really learned a lot today and feel very accomplished.

Edited by yuppicide, Thu Jul 31, 2008 6:51 AM.


#2 jwierer OFFLINE  

jwierer

    Dragonstomper

  • 746 posts
  • Location:Seattle,WA

Posted Wed Jul 30, 2008 10:22 PM

View Postyuppicide, on Wed Jul 30, 2008 11:18 PM, said:

First, DIM:

I don't really need things like

 DIM backframe=a

Does it take up more room or the same if I add that dim and do backframe=backframe+1 as opposed to just doing a=a+1?

Second, RAND:

I read up on doing something like

 a=rand

What I need is a random number between 4 and 27. How exactly do I? Is something like this possible?

loop
 a = and
 if a>27 and a<4 then goto loop
 if a<27 and a>4 then goto loop2

Will that slow things down too much because it might keep picking numbers out of my range randomizing over and over and over?

Going to bed now. Thanks again. I've really learned a lot today and feel very accomplished.

RAND will generate a number from 0 to 255 (decimal) or 00000000 to 11111111 (binary). If you do a logical AND with 11111000 (31 decimal) you'll get a number from 0 to 31 which should reduce the chances of getting a number outside of your desired range.

-Jeff

Edited by jwierer, Wed Jul 30, 2008 10:23 PM.


#3 yuppicide OFFLINE  

yuppicide

    I am the Black Knight. Give me your money!

  • 6,933 posts
  • Location:New Jersey

Posted Thu Jul 31, 2008 7:27 AM

Thanks. I should have just kept my RAND questions in my other post. What Impaler said in there solved my problem.

#4 CurtisP OFFLINE  

CurtisP

    Chopper Commander

  • 211 posts

Posted Sat Aug 2, 2008 6:55 PM

View Postyuppicide, on Wed Jul 30, 2008 11:18 PM, said:

First, DIM:

I don't really need things like

 DIM backframe=a

Does it take up more room or the same if I add that dim and do backframe=backframe+1 as opposed to just doing a=a+1?

DIM does not actually define a new variable, it just creates an alias for an existing variable. So, backframe and a will point to the same location. This means that
  a=a+1
  backframe=backframe+1
  a=backframe+1
  backframe=a+1
will all generate identical assembly code.

For me, DIMing variables to logical names is a lot easier than having to lookup what variable r is evertime. The only possible disadvantage to DIMming variables is that it will make the Symbol table larger in the ASM file, but this should not be a problem.

#5 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sat Aug 2, 2008 11:47 PM

View PostCurtisP, on Sat Aug 2, 2008 7:55 PM, said:

The only possible disadvantage to DIMming variables is that it will make the Symbol table larger in the ASM file, but this should not be a problem.
There's another possible disadvantage, which is that the new variable names will be longer than 1 character, which can make a difference if you're trying to squeeze a lot of bB statements onto a single line-- e.g., in the "then" section of an "if" statement. Of course, this isn't much of a problem, because you can squeeze a lot of characters onto a line (I'm not sure what the limit is in bB v1.0), but you might want to keep your variable names on the shorter side-- even though you can create more self-explanatory names by using longer variable names.

Michael




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users