Setting "alarms?"

For questions about using Classic.

Post » Thu Dec 31, 2009 9:16 am

Hey everyone, I'm new to Construct, and to game creation in general.

So I tried gamemaker, and I liked it. I messed around learning the basics, and created a game meant for learning purposes. I then decided to expand my horizons, and downloaded Construct.

I must say, Construct is awesome. I'm currently learning some basics via tutorials, but I've came across something I don't know how to do. I've been searching the forum, and I can't,for the life of me, figure out how to do what I want to do.

In gamemaker, there are events called alarms. One can set alarms to a certain duration, and when the alarm's duration expires, actions are carried out. Using this, you can do many things. One of the main things I used it for was delay between firing projectiles.

In gamamaker, I made an object with a variable "canshoot." On creation, canshoot was set to 1. When I pressed space, it checked to see if canshoot was set to 1, and if it was, it did the three following actions:
1.) create a projectile
2.) set canshoot to 0
3.) set an alarm to a certain duration

I then had an alarm event that would, when the set duration expired, set canshoot back to 1. This would allow me to shoot a projectile, be unable to shoot for the duration of the alarm while canshoot was at 0, and then be able to shoot again after the alarm duration expired. This kept a delay between each and every shot.

However, enough about gamemaker. This is a construct forum.

I can't figure out how to get the same results in construct. There doesn't seem to be an alarm event, or any object types related to time. I can't seem to find anything other than "every x milliseconds" which doesn't produce the same results. I just want to be able to set a timer for a length of time, and upon the time running out, have an action occur. How do I do this in construct?

I need to make my projectiles fire with delay in between each shot, regardless of whether I'm tapping the key, or holding it down.

Thanks in advance.

-Sil
B
3
G
3
Posts: 18
Reputation: 911

Post » Thu Dec 31, 2009 9:59 am

There's a timer behaviour that does exactly what you want. Add the behaviour to you sprite and then use something like.

+On Keypressed "space"
+Canshoot = 1
>create sprite "bullet"
>set variable Canshoot 0
>create timer "shoot" (you set it's name, length & other params in this event)

and then use the On Timer event.

+On Timer "shoot"
>set variable Canshoot to 1

Might not be the exact code/events but I'm away from Construct so can't double check it but it gives you a rough idea.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Thu Dec 31, 2009 10:10 am

I tried this at one point and it did not work.

Let me try it again, and I'll get back to you.

EDIT: Hmm, I think it might be working. I'll post if I'm mistaken. In the meantime, what do I type in for x and y values in object creation events to place them at random values. I thought it would be randomx and randomy but I was wrong.
B
3
G
3
Posts: 18
Reputation: 911

Post » Thu Dec 31, 2009 11:17 am

random(insert number here)

Will pick a random number between 0 & the number you entered, if you don't want to return a 0 the add +1 after closing the brackets.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Thu Dec 31, 2009 11:21 am

[quote="Silhouette":33ilzbwh]In the meantime, what do I type in for x and y values in object creation events to place them at random values.[/quote:33ilzbwh]

Use a value like Random(641)
Or maybe.. Random(LayoutWidth) for X and Random(LayoutHeight) for Y.

http://sourceforge.net/apps/mediawiki/c ... sions#Math has a description of Random():
"Random(N)
Returns a random number between 0 and N, not including N (eg. Random(3) gives one of 0, 1, 2). If N is a floating-point number, a random floating point number is generated up to but not including N, eg. Random(1.0) gives the range [0,1)"
B
3
S
1
G
3
Posts: 82
Reputation: 1,189

Post » Thu Dec 31, 2009 11:31 am

Not to hijack the thread but is there a way to pick from a series of numbers?

i.e 100,200,300,400,500 and pick one of those values at random.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Thu Dec 31, 2009 12:38 pm

[quote="Minor":s9euhbb5]Not to hijack the thread but is there a way to pick from a series of numbers?

i.e 100,200,300,400,500 and pick one of those values at random.[/quote:s9euhbb5]

There is probably a better way to do this, but what I can think of is:
Store 100,200,300,400,500 in a global text variable named numbers, then:
str(GetToken(global('numbers'),Random(NumTokens(global('numbers')))+1))

something like that.
Or convert it back with
int(GetToken(global('numbers'),Random(NumTokens(global('numbers')))+1))
or float(...)
B
3
S
1
G
3
Posts: 82
Reputation: 1,189

Post » Thu Dec 31, 2009 3:01 pm

AshyRaccoon's method is good for a series of arbitrary numbers, but for the particular sequence 100, 200, 300, 400, 500, you can use (random(5)+1)*100 :)
Scirra Founder
B
373
S
218
G
84
Posts: 23,444
Reputation: 186,078

Post » Thu Dec 31, 2009 5:39 pm

Thanks guys, I got my alarms working, and my random numbers. :D

Hmmm. What about making a boundary for my level? My plane can fly right off the screen x.x.

Also, after I add a behavior(such as 8 direction movement) is there a way I can view the behavior as events with conditions and actions, so that I may make changes? Maybe I'm barking up the wrong tree, but I figured there would have to be a way to break a behavior down into its minor parts.
B
3
G
3
Posts: 18
Reputation: 911

Post » Thu Dec 31, 2009 6:40 pm

You can place walls outside of the visible playfield.

That's an interesting suggestion for the behaviors, but currently it's not possible.

About timers: be wary, there's currently a bug where if you fire a timer from another timer's events, it crashes. Also, despite the timers using names, you can only use one per behavior or they'll get confused.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest