How do I rotate an object when condition met.

Get help using Construct 2

Post » Fri Mar 14, 2014 3:26 am

nimos100 wrote:And remove the wait and move the rotate up, and type 90/60 as how much it should rotate, it will make it rotate 90 degree every 1 sec.

"Every tick"
Rotate object 90/60 degree.


That's wonderful if I want to do something "Every Tick". I don't want to do it every tick, I want to do it only 90 times and USING A LOOP INSIDE OF A CONDITION BEING MET. That is the topic of my entire post. I want to know how to structure it.

I am basically asking everyone "Can a loop be executed inside of a condition being met?"

I don't want to use a behavior, I don't want to call a function (tried both of those still couldn't). I simply want to know how to structure a loop that fires off only once a condition is met.
B
19
S
7
G
7
Posts: 88
Reputation: 4,102

Post » Fri Mar 14, 2014 3:26 am

Here is an example, that will rotate it 90 degree every 1 second, when you click the object.

https://dl.dropboxusercontent.com/u/109921357/Rotate_test.capx
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Mar 14, 2014 3:33 am

That's wonderful if I want to do something "Every Tick". I don't want to do it every tick, I want to do it only 90 times and USING A LOOP INSIDE OF A CONDITION BEING MET. That is the topic of my entire post. I want to know how to structure it.

I am basically asking everyone "Can a loop be executed inside of a condition being met?"

I don't want to use a behavior, I don't want to call a function (tried both of those still couldn't). I simply want to know how to structure a loop that fires off only once a condition is met.


Yeah you can run a loop if conditions are made, but what you are trying to do, is not possible the way you want to do it. Because a loop is not based on the time scale you are aiming for. To make what you are trying to do work, you would need to know how fast the loop is executed, as I understand you. Which would be near impossible to figure out as I see it.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Mar 14, 2014 3:40 am

Uhm, that works, but it doesn't answer my question...unless you are trying to say "NO, you can not use a loop inside of a condition being met."

Thanks though for giving me a way to do it, but I am really trying to understand using loops like REPEAT. Like I said, I can get them to work PERFECTLY outside of a condition being met, but once I put it inside a condition being met it does not work.

Can anyone answer my question?????
B
19
S
7
G
7
Posts: 88
Reputation: 4,102

Post » Fri Mar 14, 2014 3:47 am

nimos100 wrote:
Yeah you can run a loop if conditions are made, but what you are trying to do, is not possible the way you want to do it. Because a loop is not based on the time scale you are aiming for. To make what you are trying to do work, you would need to know how fast the loop is executed, as I understand you. Which would be near impossible to figure out as I see it.


According to the manual,

Wait
Wait a number of seconds before continuing on to the next action or sub-events.

So, my thinking is that when it reaches my "Wait" it will "Wait a number of seconds before continuing on to the next action or sub-events." This is what it does outside of a condition, but inside not so.
B
19
S
7
G
7
Posts: 88
Reputation: 4,102

Post » Fri Mar 14, 2014 4:03 am

Ok ill try to explain it a bit clearer.

Loops works fine inside events, but you have to understand how C2 execute code.

When C2 reads it start from the top and go through each event and execute whatever it should.

When it reaches a loop it will repeat the loop X amount of times, before moving on.

The wait statement is a bit weird and think that might be what confuse you. The wait statement, doesn't store X amount of waits even if you repeat it 90 times. It will do it once when the wait timer is up.

Here is an example.

https://dl.dropboxusercontent.com/u/109921357/Loop%20test.capx

The Text counter on the left, have a wait of 5 seconds where the right doesn't. As you can see, the left one only updates every 5 seconds, despite it being in the same loop as the Right one. Both of them works fine however the left text will only show the count every 5 second, where the other will update constantly.

There are nothing wrong with using loops in conditions as long as you know how C2 handles them. Hope that makes it a bit clearer.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Mar 14, 2014 5:39 am

Give the sprite the "rotate" behavior(Disable at initial, set the speed you want)
and a instance variable(let's call it 'anglePrev')

Your condition > anglePrev = sprite.angle / Enable rotate
Sprite.angle=anglePrev+90, Trigger Once > Disable rotate
B
23
S
8
G
1
Posts: 172
Reputation: 2,780

Post » Fri Mar 14, 2014 2:19 pm

my attempt...

note

wait loopindex*delay
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Fri Mar 14, 2014 7:16 pm

Last edited by Yann on Sun Sep 14, 2014 7:06 pm, edited 1 time in total.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Sat Mar 15, 2014 12:35 am

shaircast wrote:Give the sprite the "rotate" behavior(Disable at initial, set the speed you want)
and a instance variable(let's call it 'anglePrev')

Your condition > anglePrev = sprite.angle / Enable rotate
Sprite.angle=anglePrev+90, Trigger Once > Disable rotate


I don't see where you disable the rotation behavior.
B
19
S
7
G
7
Posts: 88
Reputation: 4,102

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: bluesun66, jasontoups, Yahoo [Bot] and 1 guest