Random animation

Get help using Construct 2

Post » Thu Aug 24, 2017 12:10 am

Oy lads

I've got some problem with the code now and even when I was looking for a solution here on the forum, I have no idea how to fix it.

I created a sprite with animations and now I want from my game to pick randomly 1-3 animations from that sprite and save it in the 3 buttons. I setted few variables for this sprite regarding what it will have but I don't know how to create that command "random" after each turn. Since this command is used for numbers and not the texts so I can't point it like "random(sprite.AnimationName)". Any ideas how to fix this?
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Thu Aug 24, 2017 12:21 am

I'd like to know too, so the random only picks the number once.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

Post » Thu Aug 24, 2017 12:28 am

So, lets start from the beginning, what I would of done was this (this is a example of clicking a button to randomize it, but it could be anything):

Create a new global variable and have it be a number.

Button On Clicked, System -> Set Value -> (Your global variable) -> "round(random(1,3))" ( remove quotes when typing). This is setting the global variable to be a random number between 1 and 3.

Now for another event: Click on your character -> Set Animation -> (Your Global Variable name here without those quotes).

BTW, if you want I can make an example CAPX


- Ryan, Kdot Development
Owner of Kdot Development.
https://kdotdevelopment.weebly.com
B
11
S
5
G
1
Posts: 50
Reputation: 1,545

Post » Thu Aug 24, 2017 2:20 am

G, this is good. I'll try to explain on what I'm working. That capx would help a lot.

Sprite: "Planets_Types"
Vars: Food_amount, Water_Amount
Boolean: Habitable
Animation structure:
Folder: Habitable
Animations: Habit_TYPE
Folder: Unhabitable
Animations: Unhabit_TYPE

I setted everything for those vars. So the problem is only this animation. I'm using command "tokenat" to find what planet have "water" or "ice" in the name to set higher amounts of water on it.

If you need something more, feel free to ask me.
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Thu Aug 24, 2017 12:04 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Aug 24, 2017 1:29 pm

Insta, will check it tonight. I'm quite busy at the moment. I'll write back asap
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Fri Aug 25, 2017 7:59 am

Well, your logic with the Array is great. For me it is too much time to spend on the thing that is not so necessary for now :D But still, I'll use it later when I find some more time for the problem I have. Cheers!
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Fri Aug 25, 2017 2:30 pm

SputnikCZ wrote:Oy lads

I've got some problem with the code now and even when I was looking for a solution here on the forum, I have no idea how to fix it.

I created a sprite with animations and now I want from my game to pick randomly 1-3 animations from that sprite and save it in the 3 buttons. I setted few variables for this sprite regarding what it will have but I don't know how to create that command "random" after each turn. Since this command is used for numbers and not the texts so I can't point it like "random(sprite.AnimationName)". Any ideas how to fix this?



What I would do is name all animations as Anim1, Anim2 and Anim3, then when you play the animation simply type

"Anim"&global_variable

and that should work..
My first project:
Image
B
20
S
8
G
1
Posts: 172
Reputation: 2,463

Post » Fri Aug 25, 2017 3:33 pm

Rob! You made my day! Damn! :D Now I have problem with the "FTL Logic" but this is great idea!!!!!!! :D :D :D :D :D Love that! :D Unfortunately, there is small problem :D I have 2 folders with planets in the Sprite animation. Habitable and Unhabitable. Then those planets animations starts with "Habi_" or "Unhabi_" and after the planet section is the type of planet. And every of those instance variables are set for each planet in the code already (With the easiest way - (Tokenat -> look for "Unhabi", set values, ELSE set values).
SoftWork Group Ltd

Co-founders:
Robert Matik (UK Division)
Lukas Zyrek (CZ Division)

07399443703 (UK Division)

International(at)softworkgroup.wtf - for basic questions and information
Office(at)softworkgroup.wtf - email for questions about team and proposals
B
16
S
5
G
1
Posts: 49
Reputation: 1,656

Post » Fri Aug 25, 2017 3:49 pm

Oh I understand your situation. Changing the animation names everywhere is a pain in the neck. Well, then you can simply put all animation names (strings) into an array and simply pick a random animation. That would be less work in your case.
My first project:
Image
B
20
S
8
G
1
Posts: 172
Reputation: 2,463

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests