Discuss Scratch

Advantage_coding
Scratcher
90 posts

how to make a variable a fraction? example: 1/30, 2/30

please help
yavuz61035
Scratcher
500+ posts

how to make a variable a fraction? example: 1/30, 2/30

simple

setinsert variable hereto1/30
RT_Borg
Scratcher
1000+ posts

how to make a variable a fraction? example: 1/30, 2/30

Hi Advantage_coding,

What do you mean by “make a variable a fraction”?

If you mean set the variable to the value of a fraction:

setsome variableto2/30

which will give it the value 0.06666…

If you mean store an exact numerator and denominator (maybe you have a math game and want to show 1/5 + 1/2 = 7/10) you probably want to use separate variables for the numerator and denominator. (You could store the string “1/5” in a variable, but it would take a fancy loop to split this up to later treat it like a fraction).

If you're looking for something else, you might have to give more details about what you're looking for (and maybe how you plan to use it).

I hope this helps,

– RT_Borg
Advantage_coding
Scratcher
90 posts

how to make a variable a fraction? example: 1/30, 2/30

I just have a game where every 3 seconds your size increases by 10, and does my variable: “Your size”
I want “Your size” to 1/30, 2/30, all the way up to 30/30.
Here is my current code:
whenclickedrepeatuntilyoursize=300wait3secschangesizeby10changeby10

It works, I just want it to look different. Any help appreciated a lot.
legendary34678
Scratcher
1000+ posts

how to make a variable a fraction? example: 1/30, 2/30

Are you saying that when your size is 1/30 it's equivalent to being size = 10?
RT_Borg
Scratcher
1000+ posts

how to make a variable a fraction? example: 1/30, 2/30

I'm still not clear on what you want. But maybe you're looking for:

setyour sizetosize/10

for the actual value of the fraction?

Or if you're looking for something that actually looks like '1/30“, ”2/30",… to display for the user, maybe:

setyour sizetojoinceilingofsize/10join/30

– RT_Borg
Advantage_coding
Scratcher
90 posts

how to make a variable a fraction? example: 1/30, 2/30

In reply to legendary34678, yes, 1/30 = size 10, 2/30 = size 20 and so on.
SquirrelPawRocks
Scratcher
3 posts

how to make a variable a fraction? example: 1/30, 2/30

Do you just want the value of the fraction?

If you want the value, you can use it as a decimal (for example, 1/30=0.03333333333333 which has the value of 1/30 and could be used)

If you want the fraction, make two variables. Show one and hide the other. Put this code:
When green flag clicked
set Seeable fraction to (fraction)

The other variable will be for representing the fraction in decimal value.

When green flag clicked
Forever
set Unseeable fraction to (1/)
End forever loop

Powered by DjangoBB