'Pick a random object' condition for text and boxes

This forum is currently in read-only mode.
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • Right now I'm using a method by Ashley for deleting an object at random, but that method is only effective (as far as I know) for sprites.

    Both texts and boxes have 'Pick by evaluate' and 'Pick by comparison' so I was wondering if it'd be possible if they were given the 'Pick a random object' condition, just like sprites? I think it can be pretty useful, especially for texts. The option is already there for another object, so it shouldn't be too hard adding it to texts and boxes, right? (or is that the reason why they aren't there to begin with?)

    I'm using boxes (will change to sprites) and text fields for hit counters, but I won't be able to use this technique for text fields and boxes without the option (well, I'm sure there are other ways, but none this simple).

    I know it's not a grand idea, but small additions like these can be really helpful in some situations

  • Sounds like a good feature idea to me.

    In the meantime you could try this:

    Give the objects you want to pick from a new private variable.

    Use a for each loop to assign a random number to that variable for each object.

    Pick the object with the highest value for that variable.

    This has the advantage that you can use it to pick all the objects in a random sequence without repetition. Just do the above. Then set that object's "random" variable to -1 and next time you pick the object whose variable has the highest value it will be a different, but still random object. Once they all have -1 for that variable value they've all been picked and you can start over.

    Hope that was clear. Let me know if otherwise.

  • Sounds like a good feature idea to me.

    In the meantime you could try this:

    Give the objects you want to pick from a new private variable.

    Use a for each loop to assign a random number to that variable for each object.

    Pick the object with the highest value for that variable.

    This has the advantage that you can use it to pick all the objects in a random sequence without repetition. Just do the above. Then set that object's "random" variable to -1 and next time you pick the object whose variable has the highest value it will be a different, but still random object. Once they all have -1 for that variable value they've all been picked and you can start over.

    Hope that was clear. Let me know if otherwise.

    I think I understand, but texts and boxes don't have the 'Pick object with highest variable' condition too. Or are you referring to a sprite?

  • I think I understand, but texts and boxes don't have the 'Pick object with highest variable' condition too. Or are you referring to a sprite?

    Oops.

    Okay, well there's a workaround for this workaround.

    Try making an invisible sprite for each text box and put them in a container. Then assign the random variable to the sprite. When Construct picks an object in a container it picks the other objects in the container.

    Oh, I don't think I'm saying this clearly.

    Here's the wiki page on Containers.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Got it running just fine, though it'd be much easier with a couple of additional options! Hopefully this feature is implemented in the near future.

    Thanks for your help, stainsor! I really appreciate it.

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