<p>Yes, global.</p>

<p>5 variables may be 4 more than required. I think one is enough.</p>

<pre><code>Set intSensor = 0
Loop until intSensor &gt; 0
    If leftButton then intSensor = 1
    If rightButton then intSensor = 2    
    If enterButton then intSensor = 3
    If bumped1 then intSensor = 4
    If soundVal &gt; 50 then intSensor = 5
End Loop
If intSensor = 1 then moveForward(135)
. . .
</code></pre>

CC BY-SA 3.0
2013-11-08T01:48:44.637Z
2013-11-08T01:48:44.637Z
dfrevert
<p>New to NXT software. What I'm trying to do is get my motor to go one of 5 distances, but I'm not sure how to choose between those actions. What I thought of was setting 5 variables to 5 sensors. The idea is that if I activate 1 of 5 sensors (left button, enter button, right button, touch sensor, sound sensor), it will know which of the 5 variables are usable and simply does that.</p>

CC BY-SA 3.0
2013-11-08T05:07:54.840Z
Which programming language is this?
shea
<nxt><programming>
Are variables always global with NXT?
user3074
# Are variables always global with NXT?

(Asked by: username_0 on 2013-11-07)

New to NXT software. What I'm trying to do is get my motor to go one of 5 distances, but I'm not sure how to choose between those actions. What I thought of was setting 5 variables to 5 sensors. The idea is that if I activate 1 of 5 sensors (left button, enter button, right button, touch sensor, sound sensor), it will know which of the 5 variables are usable and simply does that.

**Tags:** nxt, programming

> **Comments:**
> **username_1**: Which programming language is this?  

---

## 1 answers

### Answer by username_2 on 2013-11-08. Score: 4

Yes, global.
5 variables may be 4 more than required. I think one is enough.
Set intSensor = 0
Loop until intSensor > 0
    If leftButton then intSensor = 1
    If rightButton then intSensor = 2    
    If enterButton then intSensor = 3
    If bumped1 then intSensor = 4
    If soundVal > 50 then intSensor = 5
End Loop
If intSensor = 1 then moveForward(135)
. . .


---

