How do I keep a random number after it is generated?


#1

Hi,

I want to make a simple game.

It will generate a random number, when I shake gyro sensor. if random Value==1 then Led panel will show smile face.

I don’t know how can I keep variable value after shaking gyro sensor? I tried some code blocks, but it did not work.

Do you have any idea?


#2

Hi again,

I think i solved it. I used hold block.

If you have another idea, you can share it with me, thanks.


#3

Hi Gungorhilal,

Good solution.

Why the variable?
Do you want to make life points?

Random = 1 (-1 life)
Random = 2 (Failed)

Variable = 5 (Smile green)
Variable = 3 (Smile Orange)
Variable = 1 (Red Smile)


#4

Hi Gungorhilal et T_Support,

Problem with the Random statement. Let me explain.

When the number is less than 50, 1 life is removed. However, if there is another number below 50, there is no change. There must be a number greater than 50 for there to be a change of state when a small number is obtained.

Can someone explain to me why ???
err


#5

Hi Crackel,

I think there is no problem for the Random block, it changes according to the sensor value.

The counter value will change by 1 once the input value change from false to true.
So it is normal that there must be a number greater than 50 for there to be a change of state when a small number is obtained and no change if there is another number below 50


#6

I understand the operation.
My I am a programmer and not an electronics engineer.
Can we find a way to force the change of state?


#7

Is there a way to get true when there are 2 values above 50?

I do not know how to do it. There is certainly an instruction to get the result without having to get a figure under 50?


#8

Hi Crackel,

According to your previous program, do you mean is there a way to get true when there are 2 values below 50?

Currently on Neuron APP, both the Random block and the Counter block use the same logic: change once (or count once) only when the input status changing from N to Y.

If both values below 50, the outputs of block (<=50) won’t change (output is always Y), so to the Counter block, there is no change on its input status. So I think it is difficult to change its logic to this way. But anyway, I will provide feedback of your requirement to the APP team, hopefully they will do the assessment and modify if it is necessary.


#9

Hi tec_support,

If there is no problem, it’s up to me to find a solution. Do not change the operation for my programmer logic.

Here is a solution to force the change of state that I just found with a colleague.
err

https://neuron.kynox.com/autres/astuces-code?view=article&id=54


#10

Hi Crackel,

Glad to hear that you figured out a workaround. Thanks for your sharing that!


#11