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

#1 2010-03-13 12:10:49

guy12345
Scratcher
Registered: 2010-03-13
Posts: 21

variable question IMPORTANT

<( (( <{  Shots  }> </> <{  Hits  }> )) <=> <{  Accuracy  }> )>

were would i put this?
would it even work?
if it doesnt work how can i make it work?

Offline

 

#2 2010-03-13 13:54:31

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

It will work with Hits/Shots. Here are two ways you can use that:

http://img385.imageshack.us/img385/6948/picture1om.png

Does that help?


http://i48.tinypic.com/2z5pqad.png

Offline

 

#3 2010-03-13 17:27:31

guy12345
Scratcher
Registered: 2010-03-13
Posts: 21

Re: variable question IMPORTANT

oh thanks so much!

Offline

 

#4 2010-03-13 18:08:03

guy12345
Scratcher
Registered: 2010-03-13
Posts: 21

Re: variable question IMPORTANT

wait it dont work, can you download my game, make the accuracy thing and help me?

Offline

 

#5 2010-03-13 18:55:44

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

Oh... The problem was that it didn't work when Shots was 0. (Because you can't divide by 0).
This works:
http://img94.imageshack.us/img94/1010/picture2myy.png
I just made it for percent. You can change it if you want decimals.
By the way, great game.

Is that good?


http://i48.tinypic.com/2z5pqad.png

Offline

 

#6 2010-03-13 22:58:50

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: variable question IMPORTANT

scmb1 wrote:

Oh... The problem was that it didn't work when Shots was 0. (Because you can't divide by 0).
This works:
http://img94.imageshack.us/img94/1010/picture2myy.png
I just made it for percent. You can change it if you want decimals.
By the way, great game.

Is that good?

Yeah, it works great in a remix I'm working on.  This is a GREAT game!!

Question: when Accuracy is set to a percentage, is there any way to get rid of all the decimals???  Seeing something like: 83.574639485756% just doesn't do it...  :-/

Offline

 

#7 2010-03-13 23:41:52

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

Larry828 wrote:

scmb1 wrote:

Oh... The problem was that it didn't work when Shots was 0. (Because you can't divide by 0).
This works:
http://img94.imageshack.us/img94/1010/picture2myy.png
I just made it for percent. You can change it if you want decimals.
By the way, great game.

Is that good?

Yeah, it works great in a remix I'm working on.  This is a GREAT game!!

Question: when Accuracy is set to a percentage, is there any way to get rid of all the decimals???  Seeing something like: 83.574639485756% just doesn't do it...  :-/

I messed around with it and couldn't find any trick. The only thing I can think of is just get rid of the join and put the percent outside the variable. That's not as cool though...


http://i48.tinypic.com/2z5pqad.png

Offline

 

#8 2010-03-13 23:49:29

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: variable question IMPORTANT

You could try multiplying the percent by a power of ten, rounding it (change it by -.5 first), and dividing it... I did that, and it worked.  smile


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#9 2010-03-13 23:56:18

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

Chrischb wrote:

You could try multiplying the percent by a power of ten, rounding it (change it by -.5 first), and dividing it... I did that, and it worked.  smile

Genius!  smile


http://i48.tinypic.com/2z5pqad.png

Offline

 

#10 2010-03-14 00:21:09

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: variable question IMPORTANT

Chrischb wrote:

You could try multiplying the percent by a power of ten, rounding it (change it by -.5 first), and dividing it... I did that, and it worked.  smile

And it seems to work too if you insert "round" into the script line for Accuracy given by scmb1:

Set (Accuracy) to [join (round (hits/shots * 100)) %]

But maybe we're saying the same thing!

Offline

 

#11 2010-03-14 00:22:42

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: variable question IMPORTANT

scmb1 wrote:

Oh... The problem was that it didn't work when Shots was 0. (Because you can't divide by 0).
This works:
http://img94.imageshack.us/img94/1010/picture2myy.png
I just made it for percent. You can change it if you want decimals.
By the way, great game.

Is that good?

**How do you put those screen shots into Forum postings??  They're great!

Offline

 

#12 2010-03-14 00:39:01

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: variable question IMPORTANT

Use the image BBcode for images

[img]image url here[/img]

Here is the rest of the bbcode stuff http://scratch.mit.edu/forums/help.php#bbcode


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#13 2010-03-14 09:48:02

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

Larry828 wrote:

scmb1 wrote:

Oh... The problem was that it didn't work when Shots was 0. (Because you can't divide by 0).
This works:
http://img94.imageshack.us/img94/1010/picture2myy.png
I just made it for percent. You can change it if you want decimals.
By the way, great game.

Is that good?

**How do you put those screen shots into Forum postings??  They're great!

Like archmage said, I used BBcode. To get the images, I made the blocks on Scratch and took a screen shot. Then, I uploaded them to ImageShack (I use ImageShack because you don't need an account) and used the url in my BBcode. I find that easier to do than using the forum blocks.

About rounding: If you want no decimals, use your method. Chischb's method allows to round to certain number of decimals. For this use, I think your method works fine, but when it is necessary to be a little more precise, Chischb's would be good.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#14 2010-03-14 10:01:56

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: variable question IMPORTANT

Here is Chischb's method:
http://img683.imageshack.us/img683/7586/picture3fpw.png


http://i48.tinypic.com/2z5pqad.png

Offline

 

#15 2010-03-14 11:47:15

guy12345
Scratcher
Registered: 2010-03-13
Posts: 21

Re: variable question IMPORTANT

i got it guys thanks so much. It is rounded.

Offline

 

#16 2010-03-14 11:52:25

guy12345
Scratcher
Registered: 2010-03-13
Posts: 21

Re: variable question IMPORTANT

updated the game  smile

Offline

 

#17 2010-03-14 14:30:49

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: variable question IMPORTANT

Thanks to archmage and scmb1 for the tips on BBcode and on rounding and decimals.

Extremely helpful!

(Now I understand better the coding when I "preview" a posting before submitting it.)

The Scratch Forums are terrific.

Offline

 

Board footer