Select smallest global from group

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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?)

    Thanks

  • 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

  • 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

    Then you add:

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)