# Select smallest global from group

Get help using Construct 2

### » Sun Jun 02, 2013 6:50 pm

Quick question, how do I select the lowest value from a group of global variables?

For instance, I have three globals:

G1= 100
G2= 200
G3= 500

They change occasionally.

On button clicked, I would like the lowest value returned.

How would I do this?

(Please keep scale in mind.... how would I compare 100 globals? 1000?)

Thanksbigpappapuck2013-06-03 03:32:34
B
11
S
3
G
2
Posts: 26
Reputation: 3,124

### » Sun Jun 02, 2013 8:00 pm

I would give up globals, and instead try using an array or a dictionary, and iterate over it with something like:
for (x < size of my dict)
- lmin = min(lmin,mydict.get(loopindex("x")))

Greg
B
18
S
3
G
3
Posts: 83
Reputation: 3,736

### » Sun Jun 02, 2013 8:41 pm

As long as you only need to test a few globals it should be fine, but if you plan on testing a lot then i wouldnt use it either.

But a way you can do it, is by adding a local variable or global, whatever suits you.

Lets call it:
Lowest_value_found

If G1 < G2 Set lowest_value_found = G1.value

After that you test the next one against than value.. so:

If Lowest_value_found > G3 then Set lowest_value_found = G3.value

and then you continue.

I dont think there is a way to loop through Global variables, so using this method is really bad if you have to test like 1000s, as you would have to do a lot of tests. Then you would be better off, using an array as already suggested. If you dont like arrays you can do it with a list as well.nimos1002013-06-02 20:41:59
B
45
S
12
G
3
Posts: 1,209
Reputation: 7,547

### » Mon Jun 03, 2013 3:13 am

Thanks guys.

I ended up just using the globals as: min(G1, G2, G3, G4, G5). This worked fine.

Never used the dictionary before, so that was confusing.

I did try with an array, but wasn't successful. I have the globals being saved in the array, yet I couldn't find the correct way to get the action to return the min value.

I tried min(array.CurX), but that didnt work.

Any thoughts?
bigpappapuck2013-06-03 03:39:37
B
11
S
3
G
2
Posts: 26
Reputation: 3,124