Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Help!
#1

How to randomly emit only ONE thing from a large array?

Archive: 9 posts


Hiya guys,

A logic question. I'm away from the PS3 and thinking about it, wanted your input!
Thank you very much in advance!

MY PROBLEM
I want to emit 1 random object when the player is nearby.
It should only emit ONE object, ONE time, and stop.

MY SOLUTION?
Create a Player Sensor. Wire it to an AND gate (1st input). Wire the AND gate to a Randomizer.
Wire the Randomizer to X emitters, each set to Emit Once. Wire the Player Sensor to a Counter
set to 1. Wire the Counter to a NOT gate. Wire the NOT gate to the AND gate (2nd input).

Is this right?




(BONUS PROBLEM)
I want to emit the 1st of 5 random objects when the player is nearby.
It should only emit ONE object, ONE time, and stop.
If the player leaves and comes back, it emits the 2nd of 5 objects.
Then the 3rd of 5 objects, until all 5 are emitted.
Then the whole thing shuts down.
2011-08-02 04:05:00

Author:
Unknown User


Question 1: Yes that would work but wiring the player sensor to the counter might turn it off too soon so you should use the AND gate instead.

Question 2: If you use a player sensor wire to counter set 1, Wired to the randomizer wired to an AND gate wired to an inverted counter going to the AND gate, the emitter, and an OR gate wire to the reset of the first counter. Repeat ever step after the randomizer for each emitter.
2011-08-02 06:28:00

Author:
Zero10100
Posts: 385


Question 1: Yes that would work but wiring the player sensor to the counter might turn it off too soon so you should use the AND gate instead.

Ah, that's true. I thought it would happen simultaneously, like a pulse...


Question 2: If you use a player sensor wire to counter set 1, Wired to the randomizer wired to an AND gate wired to an inverted counter going to the AND gate, the emitter, and an OR gate wire to the reset of the first counter. Repeat ever step after the randomizer for each emitter.

Wow! Took me a minute to visualize but that'll do the trick!

Thanks on both counts!
2011-08-02 06:57:00

Author:
Unknown User


I see your question was already answered. Here is a general trick, though, for situations in which you want to make sure something receives a single pulse from an otherwise persisting signal until that signal disappears and reoccurs. You wire the player sensor to a 1-shot counter that resets itself.

Of course wiring it directly to an emitter set to 1-shot (no coincidence that it is named this way) achieves the same thing, but there will be situations where you have something else happening instead of an emitter; for instance, if you wire the X-button from a controlinator to a 1-shot counter (self-resetting), then a player needs to repeatedly hit and release X for an event to keep happening, instead of just holding X.

Also, here is a nice video tutorial by CompherMC (http://www.youtube.com/watch?v=oVYY0z4HSq8) about randomizing and probability.
2011-08-02 07:09:00

Author:
Antikris
Posts: 1340


Thanks very much Antikris! I really ought to make it a rule of thumb to search for CompherMC tutorials whenever I have a logic question... and THEN ask. Heheheh.

I recently experimented with sound effects using a one-shot counter that resets, and thought "this must be what people are talking about with pulses!" but I am still not very familiar with the concept. It seems very easy to reset and continuously use something like that, but in the case of the emitter I want to be sure once one has releases its object it never gets selected again by the randomizer. Kind of like taking five raffle tickets out of a bag. I want all of them to come out, one at a time, but always in a different order.

Anyway I'll watch the video after work! Thanks for your reply. Very helpful!
2011-08-02 09:35:00

Author:
Unknown User


It seems very easy to reset and continuously use something like that, but in the case of the emitter I want to be sure once one has releases its object it never gets selected again by the randomizer. Kind of like taking five raffle tickets out of a bag. I want all of them to come out, one at a time, but always in a different order.

Open the options of the Randomizer. If you set it to 'Add', then it will light up one wire after another until all ouput wires are lit, not selecting one twice. Combine this with the 1-shot method I described above and you'll have X random picks in a collection of X of which none are chose twice. If you set the randomizer to 'Add then reset', it will keep doing this trick, resetting all of the outputs once they are all lit.

This will only work when asking for X picks in a selection of X items. For instance, if you have a collection of 10 items but want only 3 randomly picked, then reset, it gets hairy because the randomizer set to 'add' will not pick from the first 3 it selected again in the next round until at least all 10 have been selected once. So, then you do away with the 'Add' option but then you get the possibility of an item in the collection being picked twice in a round.

There was an ongoing forum thread about that once. I can't find it that fast, but here are two screengrabs I contributed to that discussion.

http://i0.lbp.me/img/ft/2a0dc575ffd566f7804b0e33e835eb14a93ba9ff.jpg

Large counter is set to 3, but as you see, only 2 items are lit up, because the randomizer decided to pick one item twice.

http://ia.lbp.me/img/ft/07a8cd68c98e88cad7f1c8886a2bccb7135c5507.jpg

The screenie above fixes it: 3 picked in a collection of 5, never an item twice in a round, always random with no randomizer reset issues.
2011-08-02 12:08:00

Author:
Antikris
Posts: 1340


So, then you do away with the 'Add' option but then you get the possibility of an item in the collection being picked twice in a round.
Yep... and to make matters worse, the Randomizer remembers it's last/current value (does not pulse), so if it selects the same value twice in a row, it will not send a new signal and can create the appearance of a gap in the sequence.
(Not entirely relevant to your situation, but an important "gotcha" to be aware of when using Randomizers).
2011-08-02 12:17:00

Author:
v0rtex
Posts: 1878


Yep... and to make matters worse, the Randomizer remembers it's last/current value (does not pulse), so if it selects the same value twice in a row, it will not send a new signal and can create the appearance of a gap in the sequence.
(Not entirely relevant to your situation, but an important "gotcha" to be aware of when using Randomizers).

I had this problem with the level I'm working on. Luckily, I think I've found a way to get around it, in my situation (haven't tested it yet, but see no reason for it not to work).

Basically, I'll have a tag sensor that will recognise the emitted object, if it notices that the object has not been emitted, it will send out another pulse to the randomiser.
2011-08-02 13:01:00

Author:
Ali_Star
Posts: 4085


Thank you guys so much! I hadn't even played with the Randomizer tweaks yet. It's learn-as-necessary for me with a lot of logic, and the Randomizer is still a conceptual part of the level while I build the rest of the stuff so I haven't gotten around to playing with it. Mostly theorizing while on the trains in the morning.

Invaluable input and discussion, thanks again.
2011-08-03 01:40:00

Author:
Unknown User


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.