comparing to range of numbers

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I have a program that randomizes number set A

    Now I want to compare if A is equal to any number ranging from x to y.

    How do I do that without making a comparison for every number individually?

  • What do you mean by number ranging from x to y ? Is it to compare A to values from 5 to 25 for ex. ?
    If so, you can add all your values in a list. During a loop you compare A to each values included in your list. Each time you compare, you delete a line in the list, and so on.
    The repetition number of your loop has to be the number of your list lines.

  • That doesn't seem to solve the problem of me having to write every number in.

    What I mean by x to y is to check if A equals any numbers in that range.

    So there's no command that works in way of

    Code
    range(x,y)

    or something similar?

  • There is. It's in the special object:
    Range(>Value<, >Minimum<, >Maximum< )

    I don't recall if the minimum and maximum values are counted in the range itself (intuition says they should be), but you can check that easily. As an example:

    +Range(Alterable value A, 5, 20)
    -Do stuff


    Alternatively, you can always set up the range manually by adding additional conditions to your event:

    +Alterable value A > 5
    +Alterable value A < 20
    -Do stuff


    If your range is actually a pool of numbers, you'll want to use a list like 2310 said but you should do it much more automated than he detailed. You certainly should not use a loop to check if the value's still in the pool. You'd do that this way:

    +Start of frame
    -Start loop "Create range pool" for (Y limit - X limit)

    +On loop "Create range pool"
    -Add line to line: X limit + LoopIndex("Create range pool")

    +User presses enter
    +Compare two general values
    ++FindString("List", Alterable Value A, 0) <> -1
    -Do stuff
    -Remove line FindString("List", Alterable Value A, 0) from List

  • Use the variable itself:

    Alterable value A = range(Alterable value A, 5, 20)


    If Alterable value A = 3
    The condition means --> If 3 = 5

    If Alterable value A = 15
    The condition means --> If 15 = 15

    If Alterable value A = 23
    The condition means --> If 23 = 20

    So the condition is only true when if Alterable value A is in a range from 5 to 20.

  • But what I need is "If alterable value A = 1" AND "Alterable value B = (any number between x and y)"

    Maybe if I explain what the hell I'm doing in full.

    I have two strings that together make a sentence. Depending on the strings the sentence either makes sense, or it doesn't.

    The first string has 5 different possibilities, governed by Value A(which goes from 1-5)

    Each of those 5 strings has 5 compatible possibilities in string 2. Governed by Value B(which goes from 1-25)

    So if A=1 then the compatible strings will be B=1-5
    A=2 compatible with B=6-10
    etc.

    The player will then click on a tick or an X to say if a sentence is correct or not.

    So I was looking for a quick way to compare A against a range of numbers in B.

    I ended up using >= and <= five times instead. Which works, I was just hoping there'd be an even easier way to do it.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!