'Pick a random object' condition for text and boxes

New releases and general discussions.

Post » Tue Jan 27, 2009 12:01 pm

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 :)
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Tue Jan 27, 2009 12:59 pm

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.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Tue Jan 27, 2009 1:32 pm

[quote="stainsor":j5qve8x2]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.[/quote:j5qve8x2]
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?
B
2
S
2
G
3
Posts: 143
Reputation: 1,536

Post » Tue Jan 27, 2009 9:38 pm

[quote="Shady":2702911v]
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?[/quote:2702911v]
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.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Wed Jan 28, 2009 2:29 am

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.
B
2
S
2
G
3
Posts: 143
Reputation: 1,536


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests