This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-02-16 09:36:49

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Please Help!

I am learning Just BASIC and I want to know the following.

If      (how is the code written, what does it do.)
then (how is the code written, what does it do.)
How can I make a variable equal a random number?


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#2 2010-02-16 09:45:05

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Please Help!

IF x=y THEN (carry out an operation)

Where x and y are either constants, program variables or strings, and "Carry out an operation" is a line of code exactly as you might put on its own.

For example

IF Score=10 THEN PRINT "You win!"

IF answer="No" THEN GOTO 200


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2010-02-16 09:47:01

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Please Help!

Mayhem wrote:

IF x=y THEN (carry out an operation)

Where x and y are either constants, program variables or strings, and "Carry out an operation" is a line of code exactly as you might put on its own.

For example

IF Score=10 THEN PRINT "You win!"

IF answer="No" THEN GOTO 200

Thanks for the help, and do you know the answer to the randomizing?


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#4 2010-02-16 10:19:03

RHY3756547
Scratcher
Registered: 2009-08-15
Posts: 1000+

Re: Please Help!

I've never used BASIC. I know how to do it in flash - though.

Offline

 

#5 2010-02-16 13:15:15

urhungry
Scratcher
Registered: 2009-07-03
Posts: 1000+

Re: Please Help!

I could have told you about the if and the then, but idk about the randomising. Did you try set variable to random 1-10?

Offline

 

#6 2010-02-16 13:34:00

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Please Help!

urhungry wrote:

Did you try set variable to random 1-10?

He needs to know how to do it in BASIC, not Scratch.

Just Googled the answer, try [variable] = Rand(min, max)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#7 2010-02-16 14:04:44

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Please Help!

It depends on teh version of Basic.

In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.

So to get a random number from 1-6, for example, there are 4 steps

1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6

Fortunately, all of that can be done as one line.  If I remember correctly it would something like:

INT (RND*6)+1


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#8 2010-02-16 14:22:44

urhungry
Scratcher
Registered: 2009-07-03
Posts: 1000+

Re: Please Help!

technoguyx wrote:

urhungry wrote:

Did you try set variable to random 1-10?

He needs to know how to do it in BASIC, not Scratch.

Just Googled the answer, try [variable] = Rand(min, max)

yes, I know, I wasn't exactly sure, but I knew it was something like that.

Offline

 

#9 2010-02-16 14:53:18

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Please Help!

Mayhem wrote:

It depends on teh version of Basic.

In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.

So to get a random number from 1-6, for example, there are 4 steps

1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6

Fortunately, all of that can be done as one line.  If I remember correctly it would something like:

INT (RND*6)+1

I believe I mentioned it's Just BASICtongue  Anyway, that always returns as one.

Last edited by soupoftomato (2010-02-16 15:53:31)


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#10 2010-02-16 15:21:40

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Please Help!

BBC BASIC?  Commodore BASIC?  Sinclair BASIC? - all are "Just BASIC" but all are subtly different.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#11 2010-02-16 21:07:43

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Please Help!

Go to justbasic.com whatever program you download there. But my dad figured it out.


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#12 2010-02-17 10:26:10

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Please Help!

soupoftomato wrote:

Mayhem wrote:

It depends on teh version of Basic.

In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.

So to get a random number from 1-6, for example, there are 4 steps

1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6

Fortunately, all of that can be done as one line.  If I remember correctly it would something like:

INT (RND*6)+1

I believe I mentioned it's Just BASICtongue  Anyway, that always returns as one.

It sounds like it is treating RND as a variable with value of zero.  Try using RND(0) so that it knows you are looking for a function result.  You can also check the documentation here
http://justbasic.conforums.com/index.cgi?board=tutorial&action=display&num=1188307611


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#13 2010-02-17 17:59:36

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Please Help!

Paddle2See wrote:

soupoftomato wrote:

Mayhem wrote:

It depends on teh version of Basic.

In the versions I know, RND or RAND will generate a random number between 0 and 0.999999 to several decimal places.

So to get a random number from 1-6, for example, there are 4 steps

1) Generate the random number using RND
2) Multiply it by the largest number (eg, 6) to get a random number from 0-5.9999
3) Round this down using the INT command, to give a whole number from 0-5
4) Add 1, to make it a number from 1-6

Fortunately, all of that can be done as one line.  If I remember correctly it would something like:

INT (RND*6)+1

I believe I mentioned it's Just BASICtongue  Anyway, that always returns as one.

It sounds like it is treating RND as a variable with value of zero.  Try using RND(0) so that it knows you are looking for a function result.  You can also check the documentation here
http://justbasic.conforums.com/index.cgi?board=tutorial&action=display&num=1188307611

Thanks for the help, but after further "research" I have figured it out, for 1-10 use RND((1)*10)10, or somehting like that, but it's included in the help so . . .


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

Board footer