Setting "alarms?"

This forum is currently in read-only mode.
0 favourites
  • 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

  • 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.

  • 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.

  • 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.

  • In the meantime, what do I type in for x and y values in object creation events to place them at random values.

    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)"

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    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(...)

  • 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

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

    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.

  • 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.

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

    The easiest way to keep things in-bounds would be to create Solid objects outside the edges of your layout for things to collide with. ("Solid" is an attribute in the properties window, just put a check next to it.)

    Such a device is known as Stainsor's Wall, after forum member Stainsor who asked the same question many eons ago.

    Anyway, if you are using behaviors for your plane then keep in mind only some behaviors have Solid collision capabilities. Ball, Car, 8Direction, and Platform behaviors can all keep from passing through Solid objects automatically.

    Custom Movement behavior can define what objects to push out of using events.

    Physics objects only interact with other Physics objects. You can define what collision type a Physics object is in the properties.

    Bullet behavior doesn't have any built-in collision for Solid objects, it'll just pass right through (unless you make events to tell it to do otherwise).

    If you are making your own custom movement with events then you will have to make your own custom collision events as well.

  • Hmm, thanks for the info on timers.

    I like the idea of placing walls outside the play field, but the things is, I don't even know how to set up impassibility. Like, how do I make a collision event that just prohibits movement. *scratches head*

    I'll keep looking around. Tutorials for construct seem so limited. Good thing the forums are very newb friendly.

    EDIT: Didn't see deadeye's post.

  • This next question applies more in game creation in general, rather than to any specific action.

    In gamemaker, your objects were stored in a list, and you could add them to the world freely. However, in construct, is seems to me that if you have an object that isn't created on start up(like a bullet), you must still place it in the layout. Although you can place it outside of the game screen, the object still exists in the game.

    For example, if I have a projectile, and I want to create it from a ship when I hit the space bar, I have to have it created in the layout already, somewhere outside of the game screen. That's all fine and dandy. However, the problem arises when I make something like a homing missile. Even though it's outside of the game screen, it will still enter the game screen and chase down a target as though it had been fired.

    I guess my question is, in simple terms, how do I deactivate objects outside of my game screen so that they do not carry out any actions? Hope my question made at least some sense.

    Edit: Also, I ran into a problem with using solid objects as boundaries.

    Apparently, at corners of the map, where two objects overlap to form a wall, I can move into the corner, and glitch through the boundaries and out of the level. If you don't know what I mean, see for yourself:

    http://www.filedropper.com/wip_1

    In the upper left corner of the screen, check the boundaries, and then try glitching through them. Fairly easy right? How do I fix that?

  • Good thing the forums are very newb friendly.

    QFT!!

    as for deactivating objects, you have to destroy them "on layout start".

    Destroying the ones out of layout is a good idea, but sadly in Construct you can't just refer to all objects at the same time unless you stuff them in a family.

    SO, what you'd do is stuff every single object in your game in a family (say, Blue) and then do

    + System: Start of layout

    + Blue: Is outside layout

    -> Blue: Destroy

    A default family would be nice, methinks. Anyways, that works, or you can just go object by object destroying them on layout start.

  • Very nice response. I'll implement that right away.

    Any advice as to my boundary problem?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)