How do I pick random value from array and delete it?

0 favourites
  • 7 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hi,

    I want to create a 3 round quiz. In each round one of 10 random sprites should be created. But no sprite should be created twice.

    For this I have dealt with (1D)-Arrays for the first time. Until now I choose a random x-value from the Array and store it in a global variable. Then the corresponding sprite is created.

    But I don't manage to delete specifically the selected x-value from the array.

    So,

    1. How can I randomly select from an array between the remaining values?

    2. And how can I specifically delete the currently selected value?

    Thanks for any help!

    held

  • Create a Local Variable "Index"

    -Set Index to floor(random(Array.width))

    -Store the Array value in to that Global

    -Delete Array index = "Index"

  • thanks already!

    sorry, I don't quite understand it yet.

    I have created a global text variable, because otherwise when deleting the array-.

    the values would simply slip. Hope I have explained it reasonably well. Here is my current test sheet. Can't I store the random array value as text in the variable?

    Thanks!

  • Here is an example see if that helps:

    https://www.dropbox.com/s/bca00qs8yw1zlzh/Array_Delete_Index.c3p?dl=0

  • Sorry, I just realised that this is the Construct 2 section:

    But you can still use the same system in C2.

    I just checked your Picture and here is a few recommendations:

    1-Remove the 0.1

    2-Save the value & Delete the index as I did

    3-Wait 0.5 and call your function

    4-On function check if "Global_Var" = "eins" etc...

    5-Remove all the trigger once as are not needed because the function is already a

    trigger once.

    6-Use Else:

    "Global_Var" = "eins"

    Else:

    "Global_Var" = "zwei"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thank you for your effort!

    I have followed your recommendations step by step. and it already does quite a lot of what i want :)

    I don't understand everything yet, but i'm working on it. I'll try to work on it from there. Maybe I'll get back to you with a question or two. If I may.

    thanks for the help so far, appreciate it!

  • thank you for your effort!

    I have followed your recommendations step by step. and it already does quite a lot of what i want :)

    I don't understand everything yet, but i'm working on it. I'll try to work on it from there. Maybe I'll get back to you with a question or two. If I may.

    thanks for the help so far, appreciate it!

    Np Glad was helpful

    Here is a quick pic of what I meant just in case:

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