"Due to the restrictions of triggers..."

0 favourites
From the Asset Store
Game Triggers is as versatile as a Swiss army knife, and will be a great resource for any type of game you're creating.
  • You can't do things that make logical sense, lol.

    I want to compare a variable. If the variable is true, then when an object is created, do some stuff. If it's not true, don't do anything.

    Construct won't let me, or just doesn't work if I manage to squeeze it in there anyway.

    Condition: On created > Do stuff

    Works fine.

    Condition: Compare Variable

    Sub Condition: On Created > Do stuff

    Broken.

    Thoughts?

  • Just use the condition compare variable as sub condition of On Created..

  • Just use the condition compare variable as sub condition of On Created..

    You might think so, but no, it doesn't matter which order I did these things.

    But that's a good example of my problem. I *frequently* encounter situations where the most straightforward and logical option tends to be a time-consuming headache.

    I really, really want to do something when an object gets created, that makes perfect sense to me.

    In this case, I'm lucky that all the objects already exist when I start the level (manually placed where I want in the editor). So I can:

    (C)Start of Layout > (C)Check Condition > (C)For Each > (A)Do Stuff

    And maybe I can presume that for things created dynamically, the condition that allows them to be created might be the same one I would want to use with the (C)On Created, and that conflict doesn't come up.

    It just feels like I spend a lot of time doing something that makes perfect sense, and then have to trial and error my way around it without ever really understanding why I wasn't allowed to do it.

  • 1: We don't know what variable, global, or instance you are talking about.

    2: Objects can't be selected until the next tick.

    3: To deal with that you can manipulate them in the event they are created.

  • 1: We don't know what variable, global, or instance you are talking about.

    2: Objects can't be selected until the next tick.

    3: To deal with that you can manipulate them in the event they are created.

    Not sure how this relates to my issue.

  • Is this what you're trying to do? Both of these work for me:

  • > 1: We don't know what variable, global, or instance you are talking about.

    > 2: Objects can't be selected until the next tick.

    > 3: To deal with that you can manipulate them in the event they are created.

    Not sure how this relates to my issue.

    Ok, just figured out why you're not getting it.

  • Is this what you're trying to do? Both of these work for me:

    Almost. The condition is a string and it's an OR.

    Global string = Text

    YourVariable = "Five"

    OR YourVariable = "Eight"

    That said, if I drop the OR block and only compare for the "Five", it still doesn't work.

    If I change the YourVariable from a string to a number and check if it equals 5, it does work. But I need to check a string, and I don't understand why checking for a string would break it if checking for a number works fine.

  • Can you post an image of your events?

  • I recently had a possible bug when using OR with a few "System > Compare Variable" conditions within the event. I debugged my project for a while, trying to understand why something didn't work, and I remember thinking "maybe it's this OR event" and I split the event up so that it was no longer an OR block, and it fixed the issue. I moved on and forgot about it until I read this post.

    Might be related, not sure, could have been my own mistake!

  • Almost. The condition is a string and it's an OR.

    Global string = Text

    YourVariable = "Five"

    OR YourVariable = "Eight"

    That said, if I drop the OR block and only compare for the "Five", it still doesn't work.

    If I change the YourVariable from a string to a number and check if it equals 5, it does work. But I need to check a string, and I don't understand why checking for a string would break it if checking for a number works fine.

    I see — I don't think you can put OR blocks and Triggers in the same block, but I might be wrong.

    I've always separated them like this. This approach also stops the code from checking "YourVariable" every loop, which can slow things down, and just check whenever a Sprite object is created.

    But ROJOHound is right, it'd easier to see what your code looks like.

  • > Almost. The condition is a string and it's an OR.

    >

    > Global string = Text

    >

    > YourVariable = "Five"

    > OR YourVariable = "Eight"

    >

    > That said, if I drop the OR block and only compare for the "Five", it still doesn't work.

    >

    > If I change the YourVariable from a string to a number and check if it equals 5, it does work. But I need to check a string, and I don't understand why checking for a string would break it if checking for a number works fine.

    I see — I don't think you can put OR blocks and Triggers in the same block, but I might be wrong.

    I've always separated them like this. This approach also stops the code from checking "YourVariable" every loop, which can slow things down, and just check whenever a Sprite object is created.

    But ROJOHound is right, it'd easier to see what your code looks like.

    The issue isn't the OR block. I'll show.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The issue is the variable being checked, not the OR block. Which makes no sense to me.

    (I've run the debug to make sure the variable was assigned correctly. But if all I do is swap those out, fails.)

    Edit: Also definitely worth mentioning that this doesn't work either, despite 1 being returned correctly.

    Edit: Also worth noting my actual project has too many events to justify doing this third option anyway. For some reason you can't just change the event type in the global variable. I sort of get how that could be a problem, but it seems way better than having to replace every instance.

  • I've tried out the first "Doesn't Work" code in your screenshot, and it seems to work fine. There might be another part of your code interfering.

    Here's the C3P

    drive.google.com/file/d/1mjCUbwdunQRdHaSdxoz7dWnTdfhJIANg/view

  • brushfe

    The Object and ObjectAbove both exist on a layout called "Objects". Seems necessary to put every object in the game into a catch-all layout to make sure I can use it when I want to (Maybe that's not necessary in C3, but it was in C2).

    On the "Level" Layout I've placed a single instance of the Object, but not the ObjectAbove. And that's where I'm checking to see if ObjectAbove has been created.

    There's only one event sheet, all the code game logic is being shown in those images.

    And like I said, I checked in debug and the variable is correct:

    Edit: Also, yes, if I create the object at start of layout it works, but the objects are being placed in the editor, so it's important the object is already there to understand why this doesn't work.

    Aren't all the objects on a layout (placed in the editor) created when the layout starts?

    Edit:

    Actually, the only thing that makes sense to me right now is that they aren't.

    If I create the object at the start of the layout it works, but if it's already on the layout it doesn't.

    Maybe it's that simple (and annoying). If the objects are placed in the editor on the layout as a "pre-arranged set of objects", then they're created before the layout starts?

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