How do I resolve this bug?

0 favourites
  • 8 posts
From the Asset Store
Match same tiles with each other as fast as you can and earn more score during a limited time!
  • Hi everyone,

    I have a strange bug occuring in one of my project. I simplify everything but it stands like this :

    ---

    object type Enemy has Health instance variable defined to 100 (default value of the object type)

    start of layout:

    • destroy Enemy

    (inside an included event sheet)

    create Enemy

    create healthBar

    set healthBar width to enemy.health

    ---

    At that moment the Enemy health value is 0 (checked in debug mode)... Which shouldn't be the case, as I never told the code to put it to 0.

    I created a new project, entered the simplified code, and it works fine ! Enemy.health is 100, and it sets healthBar width to 100. Just in my bigger project, it doesn't work, and I can't understand what's happening.

    I found two workarounds :

    disabling the event "destroy Enemy" at the start of layout makes the health be 100 at the moment the healthBar needs to read its value.

    adding "set enemy health to 100" before setting the healthbar width also works.

    I already looked a couple hour for the solution, but I can't find any spot in my code where I ask to put the enemy's health to 0. Moreover, by not destroying the object at the start it works just fine.

    Any idea of what's happening?

    Thanks !

  • It could be the order of the code. Do you have the variable before or after destroying the enemy, and in what event are the sheets included? It's possible it's being overridden.

  • The health variable is an instance variable so its base value is not defined in the code but on the object. The variable call by the healthBar object is done after destroying the enemy, as the destruction occurs at the start of layout.

    The include sheet is in an "every tick" + "trigger once while true" event that is placed just after the "at the start of layout" event, in order to create the objects I need immediately after destroying all the objects that I don't need.

    Thanks !

  • Oh, sorry, the phrasing of it made me think you set the variable to 100 in an Event, .

    Could you post up the .capx so I can run and debug it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can't do it right now, but I will do this ASAP.

    Thanks !

  • Here is the link to the simplified capx :(seems like the forum removed the link... Maybe you can help based on the description below?)

    ok, workaround : to download the capx, just enter

    dropbox.com/s/4ibtr46yhpy8avd/project88_debug.capx?dl=0

    with something at the beginning of the adress

    Curiously, the symptoms are different now, but there is still a bug with the "set width to enemy.health" action. The health bar just keep its default size and isn't resized.

    I found out another cusious thing : I defined a global variable named "level", and added an event :

    if "level" = 25 (default value) play the events.

    If I remove this condition of "if level=25", everything works fine ! The problem is that I need it, as I would like to create different enemies in regards to the level...

    ---

    Edit :

    As it seems like I can't post links, here is the detailed events and actions

    enemy has instance variable Health put to 100

    lifebar has width of 50

    global variable "level" = 25

    Event sheet 1 :

    start of layout :

    delete enemy

    delete lifebar

    include eventsheet2

    ---

    eventsheet 2 :

    if level=25 :

    create enemy

    create lifebar

    put lifebar width to enemy.health

    ---

    the result :

    it creates enemy, it creates the lifebar, but lifebar's width is still 50, not 100.

    If I remove the condition "if level = 25", everything is fine and lifebar's width becomes 100...

    (removing the "destroy" actions at the start doesn't help)

  • I can't explain why it's doing that, but for starters you have five separate System -> Every Tick events when you can move all those actions into one Event. When doing that (because there's no reason they should be separate to begin with), it works fine. The bar for me is 100%, and when I change the Enemy health value to 90, the bar is less as expected.

    Link to working version: https://www.dropbox.com/s/z23r1n8l864s3cx/project88_debug.capx?dl=0

  • Thanks a lot for your time, inquiesco. Indeed your solution works fine, but sadly it is not usable in my complete code. The reason is that I simplified the code to have only one instance of the enemy object, while in the complete code I need 2, or 3 instances.

    So, starting from your version, I duplicated the actions in order to create 2 instances in the same "every thick" event, like you suggested. It works just fine. The problem is that when I need to put the life bar's width to be the same as the health, if I put the actions in the same "every thick" event, it applies logically only to the last instance, not all. So I need to create another "every thick" event at the root, and when I do that, it doesn't work at all... :-/

    Here is the capx demonstrating the problem :

    dropbox.com/s/6s9xegcic5nyl1u/project88_debug2.capx?dl=0

    Any further idea of how I could make it work?

    I also tried to put the "set width" action in a "pick all" event at different places in the hierarchy (root level), none of it works...

    ----

    EDIT :

    Ok my problem is solved. I moved the "every thick" (or pick all, it's the same) event, containing the set width actions, at the same root level of the "level=25" event. This implies that I can't change it based on the level, but I don't need to do that. So It's solved ! Thanks a lot inquiesco for your precious help.

    Still, some things are behaving weirdly and I'll be happy if someone can tell me how I could have done that if I needed to apply this effect on only some given levels, not all...

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