whats wrong in this loop?

0 favourites
  • 9 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • wanted to do a quick loopexample, and found something strange

    if you run this group under a startcondition, it works fine

    (the loopindexes adjust the sprite position like expected)

    = examplefile

    if you run this group after start on its own, (drag group out of start)

    the positions are wrong, (but loopindex is still counted)

    can someone check this, maybe im doing something wrong

    https://dl.dropboxusercontent.com/u/61666915/looptest_group.capx

  • I think it's because when you run the group after a delay there are no instances of Sprite available for the create instance expression to reference when setting the spacing using Sprite.Width and Sprite.Height. It works on layout start because there's an instance that can be referenced before it's destroyed at the end of the start layout tick. Or something like that.... <img src="smileys/smiley4.gif" border="0" align="middle" />

  • vtrix, I believe Colludium is correct.

    I dragged the group out of the On Start of Layout section and got the incorrect spacing as you described.

    So, I disabled the line "Sprite : Destroy", and then the sprites were spaced correctly.

    Then I changed the Create object line to just create the Sprite on layer 0 at (0,0)

    and on the next line Sprite : Set position to ( 300+ loopindex("y") * (sprite.Width+1), 300 + loopindex("x") * (sprite.Height+10) )

    and that worked fine (even with the "Sprite : Destory" line re-activated). So, basically, it needs to already have a Sprite instance available to get its width and height. You just have to divide the line to create the Sprite first, then position it second rather than do it all on one line...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thats actually pretty strange, as i was under the impression, that once the object default properties are known, at the beginning of the runtime, you can destroy it, isn't this why you need to place an instance in the layout?

  • I've tried both ways and they both place in the same location. Maybe post both of you files to see if there is something else subtly going on. You can confirm the size easily by adding the Browser object and logging the width/height. The values are 15 & 30, before and after the destroy.

  • As far as i understand, the Height and Width values of a sprite don't exist in system memory if the sprite.count = 0. You can't access the Width and Height values until an object has been created, and C2 doesn't remember all of the past values of an object's parameters unless it's IID 0. Here's what I mean:

    capx

    I've always taken the need to create objects in a dump layout just to be a quirk of C2. I have made the mistake in the past of deleting instance zero of an object from my dump layout only to then have the 'default' spawn settings subsequently go crazy - size and angle - with no easy fix because I couldn't insert a new object with a lower IID than zero...

  • blackhornet , i just updated to latest beta version,

    you mean they both work for you?

    this is the link to the one not working

    https://dl.dropboxusercontent.com/u/61666915/looptest_group_fail.capx

    working

    https://dl.dropboxusercontent.com/u/61666915/looptest_group_works.capx

  • Ah, I did misunderstand what you were doing. Colludium is correct. If you destroy the object, you can't then get properties from it. Either do what AllanR suggested, or Colludium, or store the values prior to destroying.

  • now i know what my confusion is, because, if you do the same thing,

    destroy sprite, and not at start..

    sprite action , set width to sprite.width it works..

    so, the sprite objecttype does have its width saved somewhere, i guess its only available i you select the sprite.object directly

    okey, thanks for checking!

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