How do I properly create objects based on specific instances

0 favourites
  • 12 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • [attachment=0:1l9g3ziq][/attachment:1l9g3ziq]

    As you can see in the first event, I'm trying to create an object Check everytime an instance of this object is InUse (Boolean). I can have only 2 instances of this object with InUse set to True at the same time, so when I have only one instance with InUse as True, it runs once as it should be, but when I have two it starts to loop infinitly. The problem is that I can't figure out how to stop this infinity loop. I've tried other ways to do it but I'm too blind to see the solution because I'm on this for several hours and I stopped thinking many hours ago

    Thanks!

  • It is way simpler if you do "Pick Nth instance" (System expression) then in your case pick 2nd (your limit).

    You can say "if pick second is not true" > "spawn" (a second) object

    thus never having more than two instances in the first place.

    If you need them to be there first, but then destroyed, do the same with "pick 3rd instance" > if true destroy. So you will always keep two instances of your object.

    I hope it helps.

  • Can you try to put "For each Cunstomizations" on top?

    Or even better, can you give us capx?

  • >

    It is way simpler if you do "Pick Nth instance" (System expression) then in your case pick 2nd (your limit).

    You can say "if pick second is not true" > "spawn" (a second) object

    thus never having more than two instances in the first place.

    If you need them to be there first, but then destroyed, do the same with "pick 3rd instance" > if true destroy. So you will always keep two instances of your object.

    I hope it helps.

    My limit is already being handled correctly by another event and everything is working. The problem that I'm facing is just the visual part where I must tell to the player that he selected an icon/customization. Just it. I think this logic doesn't work. This method will never get the first instance. Also I have to spawn the object when it's true not the other way and I need an automatic way because I don't know if I'll allow the player to select more than two in the future.

    razorMonkey

    I tried. It's the same.

    I can't share it because it's a published project. But there is no need because everything about the problem is shown in the pic.

  • I'm losing my patience about this sh*t. I think i'll create a check object for each icon and then just play with visible and invisible checks. This not the best way to go but will work.

  • If you can replicate this in a sample capx it would be good. Not everyone has time to try and recreate the problem in a capx.

    edit: try this method. I've put in a button to toggle the 'in use' for each Customization. It retains the 'trigger once' and will work for any number of Customizations.

    [attachment=1:3iv6dfve][/attachment:3iv6dfve]

    If you want a simple checkbox it can be as simple as this

    [attachment=0:3iv6dfve][/attachment:3iv6dfve]

  • If you can replicate this in a sample capx it would be good. Not everyone has time to try and recreate the problem in a capx.

    edit: try this method. I've put in a button to toggle the 'in use' for each Customization. It retains the 'trigger once' and will work for any number of Customizations.

    [attachment=1:41z37w0b][/attachment:41z37w0b]

    If you want a simple checkbox it can be as simple as this

    [attachment=0:41z37w0b][/attachment:41z37w0b]

    I was complaining about myself trying to solve the question.

    I'll look at it. Thanks!

  • > If you can replicate this in a sample capx it would be good. Not everyone has time to try and recreate the problem in a capx.

    >

    > edit: try this method. I've put in a button to toggle the 'in use' for each Customization. It retains the 'trigger once' and will work for any number of Customizations.

    > [attachment=1:32qj9jz6][/attachment:32qj9jz6]

    >

    > If you want a simple checkbox it can be as simple as this

    > [attachment=0:32qj9jz6][/attachment:32qj9jz6]

    >

    I was complaining about myself trying to solve the question.

    I'll look at it. Thanks!

    Yeah I know, mine was just a general comment. For example I did recreate the issue (I think) so it would've been even easier for you to just copy/paste some code out to another capx (maybe).

  • >

    > > If you can replicate this in a sample capx it would be good. Not everyone has time to try and recreate the problem in a capx.

    > >

    > > edit: try this method. I've put in a button to toggle the 'in use' for each Customization. It retains the 'trigger once' and will work for any number of Customizations.

    > > [attachment=1:1n3s0hyi][/attachment:1n3s0hyi]

    > >

    > > If you want a simple checkbox it can be as simple as this

    > > [attachment=0:1n3s0hyi][/attachment:1n3s0hyi]

    > >

    >

    > I was complaining about myself trying to solve the question.

    >

    > I'll look at it. Thanks!

    >

    Yeah I know, mine was just a general comment. For example I did recreate the issue (I think) so it would've been even easier for you to just copy/paste some code out to another capx (maybe).

    Yeah I should had done that. It's because I'm rushing the update of my game so I posted the pic and then I came back to work on other stuff too

  • Can you, instead of Trigger once, put some boolean variable into each object and set it to false, put condition that only executes that actian if that boolean inside object is false and create action that puts boolean to true. That should force it to execute only once per object.

    Can you, instead of Trigger once, put some boolean variable into each object and set it to false, put condition that only executes that actian if that boolean inside object is false and create action that puts boolean to true. That should force it to execute only once per object.

  • There already is a boolean (InUse), but the trigger once is still needed so that the condition is not continuously evaluated and executed. The main reason his original events were looping is because the trigger once was not in the right place (I didn't mention that above).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • razorMonkey

    I already solved the problem, but thank you for the help.

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