I'm confused by Booleans!

0 favourites
From the Asset Store
**** Fairy cartoon game sprite character pack ****
  • I need to do the following:

    Every tik subtract .5 from hungry

    If hungry <= 0 then set boolean stomachgrowl to true

    If stomachgrowl = true play sound growl

    Play animation tummy growl

    My problem is I can't seem to find a system option for if the boolean hungry is true or false to add the follow up commands.

    I know I'm missing something but can't put my finger on it.

    Thanks

  • construct.net/en/make-games/manuals/construct-3/system-reference/system-conditions

    Is boolean set

    Test if a boolean event variable is set to true. To test if it is false, invert the condition.

  • I'm not understanding how to implement this info with what I posted.

  • My problem is I can't seem to find a system option for if the boolean hungry is true or false to add the follow up commands.

    You have found the system condition already, as it is being used in event 30 to test if true. So what's your question? If it's how to test false, right click the condition and select invert.

  • All your events run on every tick (repeated 60 times per second or even more). What's even worse is that you are using "Wait" action in such events. This means that the delayed actions will continue to run for 1 second even after the condition has become false, changing variables, stopping audio, changing animations. This will very likely break your game!

    All these checks can and should be performed in the same event where the hungryScore is changed - simply add sub-events. Then you won't even need that boolean.

    // Main event
    Character on collision with Food: Subtract 1 from hungryScore
    
     // Sub-events
     If hungryScore=1 : do this
     Else If hungryScore=2 : do some other thing
     Else If hungryScore=3 : do something else
    
  • Just sent you a few coffee's thank you for all your help.

    I think I'm following you a little bit.

    In this part of the game there are four foods (Cheese, Cookie, Sushi,Roll). I can make them one item with four animation frames and call that food. If you suggest that. But then I run into the issue of when the 'food' collides with the mouth resetting it it and having four different animation frames moving back to the original point they were dragged from.

    I have an invisible sprite called 'mouth' when the 'food' sprite collides then add 4 (full health) to the health variable called "hungryscore".

    Then set the health bar sprite to full animation frame 4.

    And make the character hungry animation invisible and turn back on the character neutral animation.

    I have a system every 1 second subtract 1 from the "hungryscore"

    When hungryscore is <=0

    Set the health bar sprite to empty animation frame 0.

    Turn off the character neutral animation

    Turn on the character hungry animation.

    I hope I'm explaining it clearly apologies if I'm not.

    Here's a video demonstrating how it works now.

    youtu.be/KNX3YaQw28o

    I'd love to simplify the code I'm trying to get my skill level and understanding up to the task.

    Here is a link to the file:

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

  • Here's a screen shot of the event sheet with the relevant code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Video looks ok, file looks ok. What is the issue ? If your problem is now that you want to simplify the code you can get rid of the repeating food events by putting food in a Family, then you just have one set of events that use the family object, will apply to all food.

  • Ah very interesting. I did not know about this.

    Thanks I'm going to play with this and see what I can do.

  • Hmm just gave that a try and can't seem to get that to work.

    I eliminated the specific code block for the cheese for example and grouped all the food items under one family.

    Changed to code as in the example but the cheese can be dragged but does not interact (disappear) when over the mouth.

  • I swapped out your event for family and it was fine, did you add the wrong cheese object to the family?

  • Yeah, many of the events could be optimized with families and functions. And you still have way too many events that run on every tick. It must be a nightmare to debug.

    Here is how you can optimize eating event - add all food sprites to a family. Move DragAndDrop behavior to the family level. Add burpAmount and fartAmount variables to the family. You can specify different values for each food type in these variables.

    Then you could have a single event for eating. Notice that the BURP and FART checks are nested under the main event and are not performed on every tick.

  • My bad, since I'm new to using families. I appreciate you introducing me to that. It will be very helpful in the future.

    Now I'm running into this issue. (I Fix one brake another I guess).

    I'm trying to have when the hunger score gets to zero to have a hunger animation play.

    The problem is it loops not the animation but the command and constantly restarts the animation so it looks like it does not play. In addition I tried also to add a stomach growl sfx but since it loops it sounds terrible.

    I need to get the animation to loop but for the hungerscore to stop subtracting after it hits zero.

  • This is what I'm trying to explain to you - when an event runs on every tick (the one highlighted on your screenshot), all its actions are repeated 60 or more times per second! That's why your animation is constantly restarted.

    And never use "wait" action in such events! Because all actions after the "wait" will continue repeating many-many times even after the event is no longer running, resetting the variable.

  • dop2000

    I tried to follow your example but I got lost on how to add the burpamount and fartamount (sounds silly when I type it LOL!) to the family.

    Am I making a new global variable? or trying to add a new instance variable to the food family? I tried that but then when I go to add it as an action it won't appear as an option.

    BTW I missed your last post and saw it after i posted.

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