[UNSOLVED] How to add to a variable itself without looping ?

0 favourites
  • 8 posts
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • For Example,

    ObjectA.width = ObjectA.width + ObjectB.width

    Here, the object A should just have the size of object B dynamically updated to it. But object A keeps getting bigger infinitely.

  • Try Construct 3

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

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

    By typing ObjectA.width = ObjectA.width + ObjectB.width you're giving Object A the width of Object A and Object B together.

    Why don't you just give object B width the width of Object B?

    ObjectA.width = ObjectB.width

    Let's say you want it to change whenever Object B width is being changed, you can do}

    Every tick --> set width ( of object B)--> ObjectA.width

    Did I get you right?

  • Hello.

    By typing ObjectA.width = ObjectA.width + ObjectB.width you're giving Object A the width of Object A and Object B together.

    Why don't you just give object B width the width of Object B?

    ObjectA.width = ObjectB.width

    Let's say you want it to change whenever Object B width is being changed, you can do}

    Every tick --> set width ( of object B)--> ObjectA.width

    Did I get you right?

    It is supposed to be the sum of their width itself.

    If width of object A = 100 and object B = 50 then object A should become 150. If object B's width changes then object A's width also need to change with respect to that.

  • So the problem is that the numbers are growing infinite?

    What about making a loop that ends after 1 loop (or more if you want to)

    Or the loop (Object b weight gets bigger) only when a condition is happening

    If I got you wrong again, can you describe to me again what are you trying to do, we more details, even screenshoots?

    Thanks

  • I usually make an instance variable called "ObjectA.self-width"

    Then go:

    ObjectA.width = ObjectA.self-width + ObjectB.width

    and change self-width as if you were changing the objects width

  • Here is the goal and the issue reconstructed as an example file. It is working in here but not in game. Here are the screenshots for the both.

    In the working example,

    The goal here is to stretch the sprite upto the text. Here is the .capx file for it.

    https://drive.google.com/open?id=1G7g_v ... Mf3xJJ5qR5

    Here is the original section which is not working an having the problem i mentioned before. Here, i am trying to extend the collider upto the text.

    Here is the full size image of the above. The one above gets cut off a bit.

    https://imgur.com/cCshU97

  • This is the wrong approach..

    You should use TextWidth property of the text object. Note, that it takes time to render and TextWidth property is not available immediately.

    See this post:

    or search the forum, there should be plenty of examples

  • Thanks for all the replies guys.

    I postponed this feature since it was giving me a headache and moved on to another and other sections of the game. I will check it out and reply once i get back to this to work on it and test it again.

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