Problem setting instance variable

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Problem Description

    It's simple, setting a value to an instance varaible does not work. When I create a Sprite, on its On Create I call function with its UID. With this UID I want to change a value of a variable, but it seems that it doesn't work. I putted another action to that sprite to check if it was not being picked, but with Destroy action(for example) it works. Also i save the X coordane and Y to a global variable and that works well.

    The Spire is called "PuntuacionObtenida".

    Attach a Capx

    dropbox.com/s/qw8z63p0nkx399a/Bug.capx

    Description of Capx

    I took a flappy bird template, you control a bat and insects come continuously from right to left. When a insect collides with the bat a number is spawed.

    Steps to Reproduce Bug

      Just ensure the bat eats an insect (but also take into account not to eat more than one, because changing the instance variable must only be done for the first number that appears). The variable bOriginalFusion remains 0 (despite setting it to true). You can disable the toggle in the destroy action and you can check that the number does not appear or see that the X and Y global variable have the sprite X and Y values.

    Observed Result

    The variable bOriginalFusion remains 0

    Expected Result

    The variable bOriginalFusion must be 1

    Affected Browsers

    • Chrome: (YES)
    • FireFox: (YES)
    • Internet Explorer: (YES)

    Operating System and Service Pack

    Windows 7 Ultimate Service Pack 1 64 bits

    Construct 2 Version ID

    163

  • When I run your project in debug mode it appears there is no PuntuacionObtenida. Looking at your code, right after you set bOriginalFusion to true you destroy PuntuacionObtenida.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When I run your project in debug mode it appears there is no PuntuacionObtenida. Looking at your code, right after you set bOriginalFusion to true you destroy PuntuacionObtenida.

    Yes, PuntuacionObtenida is spawed when an insect collides with the bat, previously it doesn't exist. The destroy action I putted to check if that action was done, just toggle it or delete to see that the bOriginialFusion value remains 0.

    Thanks,

    Sergio

  • I found a solution, I putted a wait 0.2 before calling the function. It seems that the object had no time to set its instance values, because a simple bollean=true didn't picked me the object, but if I put a wait before calling it it seems to work fine.

    Sorry if it's my fault for not knowing how it works, you can close this post.

    Thanks all,

    Sergio

  • It looks like you are only entering that loop twice. Once immediately as you start the layout, and once on first bug collision. I created a global variable called myWatch and set it to 0. Just after you set bOriginalFusion to true in your code I increment myWatch by 1. So when hit the play button it goes to 1, and when I collide with the first bug it goes to 2. (I change the font size and color inside the loop as another indicator.) Just after the first bug collision if you look at PuntuacionObtenida #0 it has bOriginalFusion set to true. If I play for a while longer hitting more bugs myWatch no longer increments.

    I had to toggle off a PuntuacionObtenida outside of the loop to see the one with bOriginalFusion set to true.

    I think I would need to spend some time digging through your code to try and understand the logic better in order to do more. I just can't do that right now since I'm at work.

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