Generating an Actor but with different Animations Each

Firiyuu77

  • Posts: 21
Hello, I'm a newbie to Stencyl, I'm currently making a scene where I would like to generate ten animations of my actor type, I would like them to be randomly shuffled each time they are generated so I made this code on the image attached.

I made an attiribute  count which takes a random integer from 1 to 11 at the first part of the looping event.

So the logic is to  show an animation that is not the generated random number for every actor creation.... So as the result I was hoping that it would show all the animations in the actor type jumbled randomly, instead all the actors I made were switching, making it seem a gif . How do I do what I want to do?

In another approach I could,

1. Generate all the actors.
2. Switch every actor to a random one, by the logic that if the animation is taken it doesnt switch to it anymore.


I want to put it into code but stencyl has this fun puzzle styled coding which is good, but I can't seem to get the hang of it of how it thinks.

Disclaimer: I ran through the crash course video. But really... i need a bit of help here, and I can find my way for the rest.



JeffreyDriver

  • Posts: 1769
I can't quite picture what's happening at the moment. Do you have all your frames in one animation? In that case, Stencyl will just loop through each frame unless you tell it otherwise.

It would be easier to have a separate animation for each. Then it's much easier to control.

Using a scene behaviour, you could have a list of all your animations and as you spawn your actors, pick a random animation from the list, then remove each animation from the list as it's selected to prevent it from appearing more than once.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Firiyuu77

  • Posts: 21
Ohhh, thanks mate for replying, but, yes following the crash course,  I had a separate animation for each, I'll attach some more pictures , it may help you picture out what I meant.

And thanks for telling me how stencyl thinks, while waiting for what you think about the behavior, I'll try to think of another solution from this perspective.

UPDATE: I just tried controlling from the a scene behavior instead from the actor, but somehow it got more complicated to me. I feel silly having this problem for a short block of code.



Note: This is a reproductive health game im trying to make, do not mistake them for awkward part names :)

« Last Edit: February 13, 2018, 03:17:53 pm by Firiyuu77 »

JeffreyDriver

  • Posts: 1769
See my attached example. I've only put three actors, but you'd place as many as you need. Your animation list will contain a list of the possible animations. You'll one for each actor you place.

Note that lists start at 0, not 1

So, we place an actor
Then we set the randomiser attribute to a random value between 0 and the number of items still in the list, minus 1.
We get the animation from the list and apply it to the last created actor.
Then we remove the animation from the list to prevent it from being selected again.

Hope this makes sense!
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Firiyuu77

  • Posts: 21
Thank you, I have made it however, the third line in every set removes the # from the list right? in my case it still repeats... I'm still trying to find out the reason. By the way, I know this isn't related, and I don't know if I should put another thread for this but how do you put spaces on the animations? I tried setting a lot of spaces between X and Y coordinates, to separate them from each other, but when I test the scenes they always end up sticking with each other.

JeffreyDriver

  • Posts: 1769
Sorry, I was wrong! Don't know how I made such a stupid mistake.

In the remove item block, just drop the randomiser attribute in there.

What do you mean by spaces in the animations? Do you want spaces between the items as in your first screenshot? That should just be a case of adjusting the Y values.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Firiyuu77

  • Posts: 21
Did you mean, like this one? http://prntscr.com/ig2it8 ? I tried it still didn't remove it from the list, so it still duplicates the other animations... about the spaces it was already fixed but thanks.  :) :) :) :) :) :) :)

JeffreyDriver

  • Posts: 1769
Yes, that should work.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Firiyuu77

  • Posts: 21
Hello Mate,

I tried playing with it, but it still would make duplicates? Please see the attached photo. Do you have any idea why is this happening?

Vaibhav Sangwan

  • Posts: 157
what type of attributes Randomiser and Randomiser2 are?

If these are of Number type,
then you should use them as:-
Randomiser as text
Randomiser2 as text

Hope it helps...

Firiyuu77

  • Posts: 21
Hello, Thank you for the reply, I tried that and it's just the same, some are repeating. Randomiser should be number I think? I think it refers to the item number which gets deleted?

JeffreyDriver

  • Posts: 1769
The second block should be: Switch animation to get item Randomiser from AnimationList

The third block should be fine as it is.

You could also do this with a loop, which would be a better solution if you're going to be doing this lots of times.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Vaibhav Sangwan

  • Posts: 157
I am not sure what you want to do exactly, but this will help you for sure
This code helped me to create an actor and getting its all animations one by one randomly:-
To do so,
I just added following code in the scene events:-
 ;) :)

« Last Edit: February 27, 2018, 02:25:48 am by Vaibhav Sangwan »

Firiyuu77

  • Posts: 21
Hello Sir Jeffrey, I tried that as you can see: http://prntscr.com/ihn8h1 but still it repeats some of the values. I tried to show it on the logs but yes... I guess the randomiser values isn't getting deleted from the list? As to why it gets repeated. Still haven't fixed it yet


The second block should be: Switch animation to get item Randomiser from AnimationList

The third block should be fine as it is.

You could also do this with a loop, which would be a better solution if you're going to be doing this lots of times.

Vaibhav Sangwan

  • Posts: 157
Do not delete items.
Instead set the value of #randomiser item from list to negative and add a repeat until looping your code to get the randomiser value more than or equal to zero.
You can see in IMAGE 2 to see how I did it.