Randomly pick a variable but not pick it twice?

  • I have a weapon with about 20 different possible variables for stats affixes such as speed, attack, defense, etc.

    I want to randomly choose 3 of those variables and upgrade it by +1.

    Problem is, that it may randomly choose that variable three times and I'll only end up with +1 upgrade instead of 3 separate ones.

    Is there a way to choose a variable but exclude it from the picking process once it has been chosen the first time?

  • create new wariable 'random choose'

    and try this: every 5 seconds set 'random choose' and type this: int(random(1,3) roll number between 1 -3

    other event:

    if 'random choose' is 1 add +1 to speed

    if 'random choose' is 2 add +1 to attack

    if 'random choose' is 2 add +1 to defense

    +

    set 'random choose' to ZERO

    but when number has been

  • use an array. Im not sure if you can copy an arrays data to another array simply so its a bit longer than doin it in normal programming but basically what you do is this:

    Make an array. This holds all your things you want randomized (in your case weapon mods)

    When you need to generate new weapon stats make a temp array and copy the original array into it.

    Now generate your random stat to add and REMOVE that from the temp array. That ensures itll never be picked more than once.

    The goal is to have quick disposable temporary arrays to deal out randomized data that can only be used the number of times it exists within the array (you add the same item twice it can get used twice)

    Its a bit more difficult to apply to C2 because like I said I dont think you can copy arrays

  • use an array. Im not sure if you can copy an arrays data to another array simply so its a bit longer than doin it in normal programming

    aridale: Consider ArraySource and ArrayDestination, two different arrays.

    Have an event (or subevent):

    For each element of ArraySource

    --> ArrayDestination.at(ArraySource.curX, ArraySource.CurY, ArraySource.CurZ) set to ArraySource.curValue

    A simple event that will loop through all the elements and copy them in the destination array.

    Of course, you use only the coordinates you need (1D or 2D arrays for example)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • yeah that would work fine.

    On startup fill your main array with all the info you need then whenever you need to randomize your values clear your temp array and then copy over all the data from the main array then randomize your selections.

    Just dont forget to remove the data from the temp array once its used and youll never get the same value twice (unless its in the array more than once)

  • If I understand you correctly you want to randomly choose 3 of 20 and then upgrade that tree different variables by 1. If that is case look this(I use 10 variables):

    http://db.tt/NuRhY5ZA

    Or you then want to randomly choose 1 of that randomly picked 3 and upgrade one of that tree? You can figure that out by first situation.

    edit: mouse click to trigger adding

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