Jump to content
IGNORED

Two questions: DIM and RAND


yuppicide

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...