Discuss Scratch

Cub56
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

Hi. As it should say on my profile, I'm working on a game called World Domination. You capture land by sending in units and I'm making a generator to decide whether or not the player wins the capture.

So, there are 3 different types of unit (squad, militia and regiment) and a
(protection)

variable that should increase the strength by a percentage. A value of 1.2 would increase by 20% for example.

I originally set it to value

(pick random (1) to (1.5))

but I showed the variable and got a value to several decimal places, not 1 decimal place. So I set it to

(pick random (10) to (15))

and need to add a script telling it to divide the value by 10. Is it possible, and if so how?

Thanks a lot if you can help.
Econinja
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

I'm sure it's this:
((pick random (10) to (15)) / (10))
Set it to that in protection and it should hopefully work!

Last edited by Econinja (July 25, 2015 20:15:37)

konichiwa123
Scratcher
80 posts

Multiply/divide a variable by a set amount?

Econinja wrote:

I'm sure it's this:
((pick random (10) to (15)) / (10))
Set it to that in protection and it should hopefully work!
Like that but I'd do it like this

change [protection v] by ((pick random (10) to (15)) / (10))
Cub56
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

Thanks! I will credit you when game is released.
GolemStolem
Scratcher
7 posts

Multiply/divide a variable by a set amount?

change [ Current Number.] by ((((☁ Current Number.)) * (2)))

I tried this and it doesn't work..
deck26
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

If it's a percentage you can't just change by in that way.

Change 5 by 1.5 will give you 6.5, not 7.5 which is 50% higher. You need to multiply the old value by the random number you're calculating to get the new value.
cs2411456
Scratcher
41 posts

Multiply/divide a variable by a set amount?

Hey, I have this kind of problem too but more complicated and in a different way. So I am trying to make a game thing where you can experiment with the speed of the pen whilst it moves from ones side of the stage. At the moment I have it like this:
forever

repeat (10)
pen down
change x by (speed)
change y by (2)
repeat (2)
pen down
change x by (join(minus)(speed)

end

endend
But the problem is, if speed is on a slider and speed changes, then is the speed is 1 then it will change X by 1 ten times, and then go back on itself without getting to the end of the page. I have tried things with variables, and I am pretty sure that I need to times it. Does anyone have a solution to this?
This is my project…
Nambaseking01
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

cs2411456 wrote:

Hey, I have this kind of problem too but more complicated and in a different way. So I am trying to make a game thing where you can experiment with the speed of the pen whilst it moves from ones side of the stage. At the moment I have it like this:
forever

repeat (10)
pen down
change x by (speed)
change y by (2)
repeat (2)
pen down
change x by (join(minus)(speed)

end

endend
But the problem is, if speed is on a slider and speed changes, then is the speed is 1 then it will change X by 1 ten times, and then go back on itself without getting to the end of the page. I have tried things with variables, and I am pretty sure that I need to times it. Does anyone have a solution to this?
This is my project…

Hello there!

Not trying to be rude, but please create your own thread about this issue. Do not use other people's thread to share your matters, it is known as “thread hijacking”. Thanks!
cs2411456
Scratcher
41 posts

Multiply/divide a variable by a set amount?

Nambaseking01 wrote:

cs2411456 wrote:

Hey, I have this kind of problem too but more complicated and in a different way. So I am trying to make a game thing where you can experiment with the speed of the pen whilst it moves from ones side of the stage. At the moment I have it like this:
forever

repeat (10)
pen down
change x by (speed)
change y by (2)
repeat (2)
pen down
change x by (join(minus)(speed)

end

endend
But the problem is, if speed is on a slider and speed changes, then is the speed is 1 then it will change X by 1 ten times, and then go back on itself without getting to the end of the page. I have tried things with variables, and I am pretty sure that I need to times it. Does anyone have a solution to this?
This is my project…

Hello there!

Not trying to be rude, but please create your own thread about this issue. Do not use other people's thread to share your matters, it is known as “thread hijacking”. Thanks!

Oh, I'm so sorry! I promise I will not do it again. Thank you for telling me. I will do as you say and create my own thread. By the way, its awesome that you like playing the piano! I am grade 4.
Nambaseking01
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

cs2411456 wrote:

Oh, I'm so sorry! I promise I will not do it again. Thank you for telling me. I will do as you say and create my own thread. By the way, its awesome that you like playing the piano! I am grade 4.

No problem, everyone makes mistakes. I am also in grade four, and yes - I recently had my piano's final exam!

Cub56 wrote:

Thanks! I will credit you when game is released.

Hello! Please close the thread if your problem has been solved to prevent necroposts.

Last edited by Nambaseking01 (June 7, 2019 21:17:02)

Za-Chary
Scratcher
1000+ posts

Multiply/divide a variable by a set amount?

Closed as resolved.

If anyone still needs help with their scripting, feel free to make a new thread and ask your question there.

Powered by DjangoBB