Topic: [possible bug] Fast loops within fast loops

In response to the object in this thread I decided to make a fast loops version of it with slightly different behavior: http://opensnc.sourceforge.net/forum/vi … hp?id=1408
Unfortunately, it does not seem to work, it seems that either fast loops do not work as I think they do or they are broken.

Here's my code:

object "ring3d"
{
    requires 0.2.0
    
    state "main" {
        let "$delta = 10" // Time between scales
        let "$timer = 0"
        let "$i = 0.1"
    
        set_animation "SD_RING" 0 // only have to set this once
        execute "ring_setup" while "$i<=1"
        change_state "wait_for_player"
    }
    
    state "ring_setup" {
        set_scale "$i" "$i"
        let "$timer += dt()"
        on_player_collision "collect"
        execute "increment" if "$timer >= $delta"
    }

    state "increment" {
        let "$i += 0.1"
        let "$timer = 0"
        // play_sample "samples/1up.ogg" // This was here so I could hear each increment stage
    }
    
    state "wait_for_player" {
        on_player_collision "collect"
    }
    
    state "collect" {
        add_collectibles 1
        play_sample "samples/ring.wav"
        execute "ring_removal" while "$i<=2.5"
        change_state "destroy"
    }
    
    state "ring_removal" {
        set_scale "$i" "$i"
        let "$timer += dt()"
        execute "increment" if "$timer >= $delta"
    }
    
    state "destroy" {
        set_animation "SD_RING" 1
        on_animation_finished "destroy_2"
    }
    
    state "destroy_2" {
        destroy
    }
}

As you can see, I have set $delta to a ridiculously high number, yet still it seems that all my increments are executed at the exact same time.  I only want such a state to execute when it's condition is true, and because of logic within the if's execution it ceases to be true when running so that count up may begin again.

Am I doing something wrong?  If so, please post because I'm not seeing it immediately.

Edit: I am currently messing around with it some more, and it seems that $timer is reaching 10 at record pace when I don't reset it.  Has the way dt() works changed recently or something, because it seems to be reaching 10 in tenths of a second rather than seconds.  Perhaps fast loops change the model for how it works, or perhaps the internal engine code has changed for it, either way it hits 10 in what seems to be less than a tenth of a second.

Last edited by lunarrush (2012-10-05 19:16:30)

If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Re: [possible bug] Fast loops within fast loops

the code was pretty cool, thanks. Over the gif is horrible, I was clicking print Screen tongue. I will soon post the gif right.

Last edited by MatheusRRR (2012-10-05 19:21:39)

Re: [possible bug] Fast loops within fast loops

Matheus, i think you are mixing up your posts.

Lunar,

try printing all variables with textout to see where the problem lies.

and try moving this to "main"

execute "increment" if "$timer >= $delta"
https://image.ibb.co/kuSYrm/SD_sml.pnghttps://image.ibb.co/kHq8P6/SeD_sml.pnghttps://image.ibb.co/cJf8P6/LTot_W_sml.png

Re: [possible bug] Fast loops within fast loops

lunarrush wrote:

I am currently messing around with it some more, and it seems that $timer is reaching 10 at record pace when I don't reset it.

It should do exactly that. To simplify the analysis, suppose that the player is not colliding with the object.

1. you let $timer=0 and $delta=10. Hence, ($timer >= $delta) is false.
2. you let $i=0.1. While $i<=1, you do:
2.1. add dt() to $timer.

Since dt() is being added to $timer in a while loop, $timer will reach 10 within a single frame; certainly much less than 10 seconds.