# Help with Variables detection

To make this post pretty short, I’ll try to make it as concise as possible. Basically, I want to check when a variable changes, is there any to do that? Like if I have a variable called “num” that’s currently at value 2 and if that value changes to any other number, then the computer will execute the code. Is there any way to do that? Ik you might be able to do it with 2 variables, but is there any easier way?

16 Likes

hey there - welcome back!

hmm to answer this question, you could always have a…
repeat forever/when 7=7 with set text[variable]!

for this, sounds like you could have when variable is not equal to 2 - complete whatever action!

4 Likes

When (var 1) ≠ (var 2)
Run code
Set (var 1) to (var 2)

3 Likes

If you want to check whether or not a variable equals a certain value, do When [Variable] equals [Value].

2 Likes

When rum is not equal to 2, do code.
Wow welcome back I’m CB Studios! I joined the forum 3 months ago

1 Like

For that, you’ll need two variables: one for the previous value, and one for the current value

When (previous) ≠ (current)

• Do Something such as [Set text to (Variable Changed) color (RGB:0,120,240)]
• Set previous to current //Prevents Constant Execution of Rule.

This is basically the only way to detect changes from any number. A single variable will be able to detect only a change from a specific number

1 Like

Oh, never mind. You wanted to know when the variable’s value changes, not changes to a certain value.

Ok thx guys.

1 Like

Welcome back, Ambush!

And if you want to keep track of when a variable changes you can always use this code:

When game starts: Repeat forever: set text to (variable)

There are probably some other ways as well.

1 Like