Author Topic: Help Requested: Pausing to let a loop play  (Read 7014 times)

0 Members and 1 Guest are viewing this topic.

Offline claudehuggins

Help Requested: Pausing to let a loop play
« on: February 23, 2016, 10:01:34 AM »
First of all, I want to thank the community for helping me out with my last questions. Everyone was very patient and helpful and I appreciate it a ton -- my problem was solved and now behaves exactly the way I wanted it to.  ;D

I have another question, this time concerning views.
I have a view set up (view.002) of ego getting shot that I want to use for a death sequence. I wanted it to be drawn out and overly dramatic as part of the joke, so I animated 4 loops and set some print statements to separate them with some narration. My issue is that I have no idea how to have the script wait for the loop to reach the last cel before calling the print statement.

Here's my script:
Code: [Select]
(send gEgo:view(2)loop(0)cel(0)) //ego turns around, this one isn't animated so I didn't set a cycle, but I'd like there to be a short pause, just enough for the player to notice the view changed.
Print(500 2)
(send gEgo:view(2)loop(1)cel(0)setMotion(NULL)setCycle(Fwd)) //ego looks around nervously
Print(500 3)
(send gEgo:view(2)loop(2)cel(0)setMotion(NULL)setCycle(Fwd)) //ego shrugs
Print(500 4)
(send gEgo:view(2)loop(3)(cel(0)setMotion(NULL)setCycle(Fwd)) //ego is shot
= dyingScript //yadda yadda death code

In this case, the "pause" between print statements is so fast that the loop never has time to play. I was wondering if there was something I could do to tell the code to wait until the last cel has been reached before continuing with the script.


A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".

Offline MusicallyInspired

Re: Help Requested: Pausing to let a loop play
« Reply #1 on: February 23, 2016, 11:21:16 AM »
I'm a little rusty on my SCI scripting, but I'm pretty sure this is correct. Somebody can correct me if I mess up somewhere. You need to use the changeState method of the room script. Or make a new script instance with its own changeState method and call it when it's supposed to trigger. The way you've got it rigged up now everything is happening all at once instead of in turn like you want, that's why animations won't play out. Usually you would time each state by putting a "= cycles 5" or something line in there, but what you can do is have animations trigger the next script case when they're finished by cuing the script in the setCycle functions. Here's what it would look like:

Code: [Select]
(instance egoShotScript of Script
    (properties)
    (method changeState newState
        (switch (= state newState)
            (case 0 = cycles 2 // This state will last for 2 game cycles (very fast, basically instantly)
                (send gEgo:view(2)loop(0)cel(0))
                Print(500 2)
            )
            (case 1
                (send gEgo:view(2)loop(1)cel(0)setMotion(NULL)setCycle(End self))  // We use "end" because we want it to animate to the end of the animation not continuously animate forever (which Fwd does). "self" in this case in the setCycle method tells the script to cue the next state when it's finished, you could cue any script here, but we want the next state in the same script, so we put "self"
                Print(500 3)
            )
            (case 2
                (send gEgo:view(2)loop(2)cel(0)setMotion(NULL)setCycle(End self))
                Print(500 4)
            )
            (case 3
                (send gEgo:view(2)loop(3)(cel(0)setMotion(NULL)setCycle(End self))
               
            )
            (case 4
                = dyingScript //yadda yadda death code
               
            )
    )
)

You'd throw this block of code at the bottom of your room script and call it from wherever this is supposed to happen with:

Code: [Select]
(self:setScript(egoShotScript))
« Last Edit: February 23, 2016, 11:24:16 AM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Kawa

Re: Help Requested: Pausing to let a loop play
« Reply #2 on: February 23, 2016, 11:23:22 AM »
Haha, Brandon. You beat me to it! I had this whole thing prepared and all  :D

Offline MusicallyInspired

Re: Help Requested: Pausing to let a loop play
« Reply #3 on: February 23, 2016, 11:35:32 AM »
Lol I knew I'd be racing someone.
Brass Lantern Prop Competition

Offline claudehuggins

Re: Help Requested: Pausing to let a loop play
« Reply #4 on: February 23, 2016, 11:44:40 AM »
Code: [Select]
(instance egoShotScript of Script
    (properties)
    (method changeState newState
        (switch (= state newState)
            (case 0 = cycles 2 // This state will last for 2 game cycles (very fast, basically instantly)
                (send gEgo:view(2)loop(0)cel(0))
                Print(500 2)
            )
            (case 1
                (send gEgo:view(2)loop(1)cel(0)setMotion(NULL)setCycle(End self))  // We use "end" because we want it to animate to the end of the animation not continuously animate forever (which Fwd does). "self" in this case in the setCycle method tells the script to cue the next state when it's finished, you could cue any script here, but we want the next state in the same script, so we put "self"
                Print(500 3)
            )
            (case 2
                (send gEgo:view(2)loop(2)cel(0)setMotion(NULL)setCycle(End self))
                Print(500 4)
            )
            (case 3
                (send gEgo:view(2)loop(3)(cel(0)setMotion(NULL)setCycle(End self))
               
            )
            (case 4
                = dyingScript //yadda yadda death code
               
            )
    )
)

You'd throw this block of code at the bottom of your room script and call it from wherever this is supposed to happen with:

Code: [Select]
(self:setScript(egoShotScript))

I'm getting a "expected method declaration" error when I attempt to compile my code. The error points to the "(method changeState newState" line. Any idea what could be causing this and how to fix it?
A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".

Offline MusicallyInspired

Re: Help Requested: Pausing to let a loop play
« Reply #5 on: February 23, 2016, 11:48:06 AM »
Sorry, that line should be:

Code: [Select]
(method (changeState newState)
Brass Lantern Prop Competition

Offline Cloudee1

Re: Help Requested: Pausing to let a loop play
« Reply #6 on: February 23, 2016, 11:53:32 AM »
That usually means there is a missing bracket somewhere. Without seeing your room script, that will be hard to figure out from here.

But basically, check your room script layout.

(instance ...1
  (method...1
  code stuff
  )//end method
)// end instance
(instance ...2
  (method...1
  code stuff
  )//end method 1
  (method...2
  code stuff
  )//end method 2
)// end instance 2
 
Basically, one method has to end before the next one begins, and likewise, one instance has to end before the next one can begin. If looking over that doesn't help, feel free to stick it all up and we'll figure it out.

Another thing you can do is pick a closing ) that you have and put another one in front of it. The script compiler should highlight the opening bracket for you. If it isn't where you are expecting it to be, then you have found your trouble area. Don't forget to remove the closing bracket you just added because really you are just using it to double check your statements and just randomly throwing in a few extra willy nilly isn't going to help you
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: Help Requested: Pausing to let a loop play
« Reply #7 on: February 23, 2016, 11:56:06 AM »
I missed brackets on the first method line lol.
Brass Lantern Prop Competition

Offline claudehuggins

Re: Help Requested: Pausing to let a loop play
« Reply #8 on: February 23, 2016, 12:11:36 PM »
Well, that works!
....To an extent, anyway.
For whatever reason, instead of changing to view 2, ego remains on the view he was previously on. So in my game, when I run the script, instead of playing the animations between each text (which works fine by the way), he just walks in place in various directions.

I have no idea what could be causing this; I've confirmed multiple times that I specified the correct view.

Derp, I had a doit method set to change ego's view depending on what control color he's standing on (changing to a brighter version of his sprite when standing under a light). I can easily take this out without ruining the gameplay as it's simply an aesthetic effect, but would there be any way around this? Perhaps setting a boolean and turning it off when the script activates?
A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".

Offline claudehuggins

Re: Help Requested: Pausing to let a loop play
« Reply #9 on: February 23, 2016, 12:17:34 PM »
Ok, another problem I noticed while trying to fix the doit issue (I have it commented out for the time being)

He goes into the first position just fine, but case 1 never triggers. He turns around, and then when I dismiss the text window to go to the next part of the sequence, it just sort of stops, and I can "walk" around with view 2. Is it something to do with the fact that loop 1 is only one frame?
A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".

Offline MusicallyInspired

Re: Help Requested: Pausing to let a loop play
« Reply #10 on: February 23, 2016, 12:17:53 PM »
Yes, a a local boolean would be my first choice and then set a condition when walking on certain control colours to only change views if the death boolean is false.

EDIT: First of all, I forgot that you should probably disable player control for the duration of the death script, or you'll be able to do other things. Secondly, try setting the cycles a little longer for that first case that's freezing (like = cycles 4) and move that first Print statement to the beginning of the next case instead just in case.
« Last Edit: February 23, 2016, 12:20:07 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Cloudee1

Re: Help Requested: Pausing to let a loop play
« Reply #11 on: February 23, 2016, 12:19:23 PM »
Very easy and yes, a local boolean variable would be perfect

Up at the top, create a local variable
 egoDead = FALSE

Now, use this variable in your doit method that is forcing ego to a specific view, just add an if statement around what you already have going on there.

 (if(not(egoDead))
   What you already have...
 ) // end if not ego dead

and then finally, when your ego get's shot, you could stick this in case 0 of what Brandon had going for you, above where you set the ego's view. A better place would be wherever it is that you called the changestate, that way it is yours to control from the get go.

= egoDead TRUE

and that should be all it takes to steal control back from the doit method.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline claudehuggins

Re: Help Requested: Pausing to let a loop play
« Reply #12 on: February 23, 2016, 12:37:50 PM »

EDIT: First of all, I forgot that you should probably disable player control for the duration of the death script, or you'll be able to do other things. Secondly, try setting the cycles a little longer for that first case that's freezing (like = cycles 4) and move that first Print statement to the beginning of the next case instead just in case.

It works like a charm! Thank you all so much for your help  ;D
A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.05 seconds with 24 queries.