Voytek's Recent Forum Activity

  • This is how it works fine in case you need it. This one is solved.

  • Thanks a lot, I have finally made it work. Now, I am stuck at having a better version of randomiser. I stumbled upon Fisher Yates, but I cannot reuse it. Have a look here with image and capx.

    construct.net/en/forum/construct-2/how-do-i-18/fisher-yates-work-function-148857

  • I have found this tutorial:

    construct.net/en/tutorials/implementing-fisher-yates-290

    It works fine in itself. However, I cannot reuse it in a function. Can you make it work inside a function so that i could reuse it?

    I tried passing the array with a array.uid, but it still does not work.

    BTW, this is a javascript Fisher Yates, which works fine.

    var array= [1,2,3];
    
    function shuffleArray(array) {
     for (var i = array.length - 1; i > 0; i--) {
     var j = Math.floor(Math.random() * (i + 1));
     var temp = array[i];
     array[i] = array[j];
     array[j] = temp;
     }
     return array;
    }
    var x=shuffleArray(array);
    alert(x);

    I would expect something like this to work each time I click the button:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for contributing, but it is not what I need. I basically want to destroy sprites in a row without destroing other sprites. I will allow bullet to pass other sprites from a different row till the chosen row is destroyed but according to a random order based on a unique random number. Like I showed.

    The first sprite to be destroyed can be in any row and it can be any sprite in the row. But The choice of the sprite to be destroyed first is based on a unique generated random number from 1 to 3. that is why i have instance variables to check them against the random number. Once a sprite is destroyed correctly, i want a player to destroy another sprite but this time in the very same row based on a different unique number i.e. no the one from the first shooting. Then the last sprite is to be destroyed in the same row.

    In other words, once a player hits one sprite correctly, because for instance he gets random number 1 and green sprite is the one with instance variable 1, I further want the player to stay committed to destoying other sprites in the same row. The player will have two other sprites to choose. However, he is not free to choose, because he is given a random number again, and he has to identify the sprite to destroy. At last he is left with the last sprite in the row to destroy.

    And the cycle repeats.

    Right now i have tried different things and my capx is a mess. Will try to do something about it if no one gets what i intend to do.

  • To solve my problem, I tried:

    I tried calculating uid, but it is useless, because uid get recycled.

    I tried adding family instance variable when red gets hit but that family instance variable affects all green sprites, and it does not differentiate sprites.

    Description of a problem:

    I spawn 3 sprites in a line, their order in a line is random. There is green sprite (Green), red sprite (Red) and blue sprite (BLue) in rows that get spawned like so:

    ..............Red Green Blue (dots.... represent blank space)

    Green Red Blue

    ...................Green^ Red* Blue’’

    Blue Green Red

    A player will shoot at the sprites from the bottom. I have got this ready.

    Sprite green has instance variable = 1, sprite Red = 2, sprite blue = 3

    Then I generate random number 1, 2 or 3.

    Let’s say I get 2. Then I want a player to shoot any of the Red Sprites, because they have instance variable 2, it is possible, because they move.

    Let's say a player succeeds hitting sprite Red with an asterix Red*. I destroy the Red*, then I generate a number either 1 or 3.

    Let’s say I get 1. NOW I want a player to hit ONLY sprite red’s Green^ neighbour EXCLUSIVELY. THIS IS WHERE THE PROBLEM IS. I CAN'T do it, because I do not know how to pick this particular sprite. I want the player to keep shooting but only hitting Green^ takes effect. Once a player would do it, I destroy Green^.

    Then I want a player to shoot sprite marked with quotation marks Blue’’ EXCLUSIVELY just like the Green^ described above. I CAN'T do it.

    After that the whole logic starts from the beginning with a random number selected.

    I have got the shooting ready. I cannot do the destruction in the right order as described above.

  • You do not have permission to view this post

  • You do not have permission to view this post

  • Thank you, it appears to work!

  • I know that in javascript it is possible to have a string and then put it into an array:

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Break a string and convert it into an array of words.</title>

    </head>

    <body>

    <script>

    var str = "there is a cat with a lack of dog in the attic";

    var words = str.split(" ", 10);

    for (i=0; i<words.length; i++){

    console.log(words);

    }

    </script>

    </body>

    </html>

    I know how to get input from a text box, but I do not know how to break the string from that input into array.

    I would like to be able to do the same as the code above, preferably rbe able to set a limit as well, in my example, it is 10.

    In the end I would like to store each sentence as a different array, so I imagine I will have one array

    and I would be filling it with arrays deriving from strings coming from the input.

    How can I achieve all that, perhaps i might be able to figure out storing these arrays but i am already blocked, because i do not know how to convert a string into array in the first place, just like described above, but in construct.

    Thank you in advance!

  • Thanks for your feedback. Your contribution has showed me what could be done.

  • I would like a player to decide on sprite images and be able to upload them into a game before the game begins.

    Additionally, would it be possible to have the image sprites trimmed to certain size or keep them within dimensions of a certain scale during the upload process?

  • Thank you for your exhaustive answer. It seems I should manage to make it work with the information you provided. You are incredibly knowledgeable in the field!

Voytek's avatar

Voytek

Member since 19 Jul, 2016

None one is following Voytek yet!

Trophy Case

  • 8-Year Club
  • RTFM Read the fabulous manual
  • Email Verified

Progress

10/44
How to earn trophies