I'm confused by Booleans!

0 favourites
From the Asset Store
**** Fairy cartoon game sprite character pack ****
  • Create a function, call it only when HungryScore is changed, and put all checks inside the function. This way they will not run on every tick! And you will have a single event where all changes to the HungryScore are handled, not a hundred of events all over the project, which will make debugging a lot easier.

    This is just an example of what it may look like, don't copy it to your project:

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

    Yes, these should be instance variables defined on the family. They will be accessible on the family itself and on all its members. Say, you can use Food.burpAmount, or you can use Food_Cookie.burpAmount

  • Yikes that's a bit complicated I don't understand how to get that number amount field under that Onfunction ChangeHungryScore line.

  • Press P to add a function parameter. Or right-click

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I know you said don't copy but I'm kind of stuck and trying to catch up. I ran the code you gave as an example it deducts .5 and shows on the health bar but then stops subtracting and stays there.

    Thanks for being patient with me. I'm trying to learn as best I can.

    Any ideas?

  • I ran the code you gave as an example it deducts .5 and shows on the health bar but then stops subtracting and stays there.

    It should stop once the variable reaches 0. If you want to allow negative values, then remove the "Set HungryScore to clamp()" action.

    Also, you probably still have lots of other events in the project that can change the value of HungryScore variable and mess with your test.

  • I deleted all references to hungerscore on all other event pages it's just the eat event page. Still not working.

    drive.google.com/file/d/1_YdmMttmQytx2hRCvZ-SeejYtIv68WV8/view

    If you want to take a look.

  • "Event eat" sheet belongs to Eat layout, so events from it will only work in Eat layout. If you want these events to be available in other layouts, you need to include "Event eat" sheet there - right-click -> Include event sheet.

    This is not required if you only want to call the function from other layouts.

    .

    When I run Eat layout directly, I can see in the debugger how HungryScore decreases by -0.05 every 5 seconds.

    .

    Also, events 10-15 are not needed. You already have "Sprite_Health: Set animation frame to int(HungryScore)" action which updates the health bar.

    Events 16-26 need to be inside the function.

  • Made the changes you suggest but the health bar moves slightly then stops with no further changes. Can't pin down what I'm doing wrong.

    Edit: Actually I see it (the health bar) going down it's just slower that's why I didn't catch it. But when it hits zero the hungry animation is not playing. I changed the line 6 to -.5 instead of -.05 and its working now.

    Thanks so much.

    Now I've got to get it working across the other layouts.

  • Don't rely on the health bar, it can show 0 when the value is really 0.95

    Run the game in Debug Mode (Shift+F4 or Shift+F5) and check the variable value there.

  • Got it running!

    The thing was I had the line 6 set every 5 seconds to subtract .05 when I changed that to .5 it sped up enough for me to see it faster.

    Thanks so much!

    Now I just have to get it working in the other event pages.

  • Got it included as a test on the main dashboard page but I'm noticing that when I first go to either page (Main dash or eat) the health bar is empty then after 5 seconds it fills where it is supposed to be.

    Is there a way to have the health bar show the proper status before the function call five second command?

  • Is there a way to have the health bar show the proper status before the function call five second command?

    Yes, you can call the function on start of the layout with amount=0. It will not change the variable, but will update the health bar and everything else. Or you can simply update the health bar on start of layout:

    -> Sprite_Health: Set animation frame to int(HungryScore)

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