Discuss Scratch

blakelarson19
Scratcher
24 posts

Pick number a or number b?

zp100 wrote:

blakelarson19 wrote:

Thanks guys for the advice, but earlier in the thread I found a solution,
if <touching [D1 v] ?> then

set [Numer Help v] to [(pick random (1) to (2)) ]
if <(Number Help) = [1]> then

set [Wolf Direction v] to [2 ]
if <(Number Help) = [2]> then

set [Wolf Direction v] to [4]
end

end

end
It would be much easier to just do
if <touching [D1 v] ?> then
set [Numer Help v] to ((pick random (1) to (2)) * (2))
end
It would give the exact same result, but with fewer blocks and less space.

That is true, and a good idea, unfortunately I already spent hours using the other one into my entire code.
Mole_Gaming
Scratcher
100+ posts

Pick number a or number b?

define Pick either (a) or (b)
set [output v] to ((b) + (((a)-(b))*(pick random (0) to (1))))

Last edited by Mole_Gaming (May 20, 2016 19:37:30)

zp100
Scratcher
100+ posts

Pick number a or number b?

Mole_Gaming wrote:

define Pick either (a) or (b)
set [output v] to ((b) + (((a)-(b))*(pick random (0) to (1))))
That's what I said earlier.
Dan0510
Scratcher
100+ posts

Pick number a or number b?

Hello!

Another solution for the problem could also be
(letter (pick random (1) to (2)) of [37])
That's the easiest solution I can imagine, it doesn't even require much math, but works for one digit numbers only

Last edited by Dan0510 (May 23, 2016 08:58:46)

deck26
Scratcher
1000+ posts

Pick number a or number b?

Dan0510 wrote:

Hello!

Another solution for the problem could also be
(letter (pick random (1) to (2)) of [37])
That's the easiest solution I can imagine, it doesn't even require much math, but works for one digit numbers only
True, it's more limited, but it's a nice alternative and potentially useful for choosing between more than 2 values.
Mole_Gaming
Scratcher
100+ posts

Pick number a or number b?

zp100 wrote:

That's what I said earlier.
But this is a more simplified and easier-to-use version
MegaMiner260
Scratcher
6 posts

Pick number a or number b?

I also had this sort of problem. one solution is to set it from 2 random numbers not having anything to do with 3 or 5, like this:

when I receive [ whatever it needs v]
set [variable v] to (pick random (30) to (31))
if <[variable] = [30]> then
set [variable v] to [3]


else
if <[variable] = [31]> then
set [variable v] to [5]
end
end

I hope it helps
MegaMiner260
Scratcher
6 posts

Pick number a or number b?

I also had this sort of problem. one solution is to set it from 2 random numbers not having anything to do with 3 or 5, like this:

when I receive [ whatever it needs v]
set [variable v] to (pick random (30) to (31))
if <[variable] = [30]> then
set [variable v] to [3]


else
if <[variable] = [31]> then
set [variable v] to [5]
end
end

I hope it helps
Harakou
Scratcher
1000+ posts

Pick number a or number b?

Thanks for offering your help, but this thread already has quite a few suggested solutions and it's well over a year old. I don't think an answer is necessary anymore. Please check the date and make sure the thread is still relevant before replying. Thanks!

Powered by DjangoBB