Jump to content

Photo

Adding a visual cue to my Compass Beep Script.


  • Please log in to reply
5 replies to this topic

#1 Demonlink

Demonlink

    Lurking in the shadows...

  • Members
  • Real Name:Miguel
  • Location:Wouldn't you like to know?

Posted 07 July 2021 - 02:34 PM

const int COMPASS_SFX = 79; //Set this to the SFX id you want to hear when you have the compass.
const int COMPASS_VISUAL_CMB = 48;
const int COMPASS_VISUAL_CSET = 7;

ffc script CompassBeep{
     void run(int item, int specialitem){
          if(GetLevelItem(LI_COMPASS)){
               if(!Screen->State[ST_ITEM] && (item>0)){
                    Game->PlaySound(COMPASS_SFX);
                    for(int i = 120; i>0; i--){
                         Screen->FastCombo(7,0,0, COMPASS_VISUAL_CMB, COMPASS_VISUAL_CSET,OP_OPAQUE);
                    }
               }
               else if(!Screen->State[ST_SPECIALITEM] && (specialitem>0)){
                    Game->PlaySound(COMPASS_SFX);
                    for(int i = 120; i>0; i--){ 
                         Screen->FastCombo(7,0,0, COMPASS_VISUAL_CMB, COMPASS_VISUAL_CSET,OP_OPAQUE);
                    }
               }
          }
     }
}

So, I have this script that plays an sfx whenever you have the dungeon's compass. But I want to add one more thing, a visual cue (suggested by Shane). I have the blinking combo made, but my main problem is that I only want it to be shown for about 3 seconds and then have it disappear until you revisit the screen (given you haven't collected the item yet).

 

I thought that with a for loop it would do that, but it doesn't. I imagine that it does that since the script runs only for a single frame? It does get drawn, but only for a split second, then it disappears...

 

Thanks for any given help. 


  • Shane likes this

#2 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 07 July 2021 - 03:06 PM

You've got almost everything right here. The only issue is, like you pointed out, the for loop only runs for one frame. That's because scripts will do everything in a single frame unless you explicitly tell them to wait a frame. So all we have to do is take your while loop and add an instruction for it to do that.

 

                    for(int i = 120; i>0; i--){
                         Screen->FastCombo(7,0,0, COMPASS_VISUAL_CMB, COMPASS_VISUAL_CSET,OP_OPAQUE);
                         Waitframe();
                    }

 

Easy peasy. Now, for 120 times, it'll draw the combo, then wait for the next frame.


  • Shane and Demonlink like this

#3 Matthew

Matthew

  • Administrators
  • Real Name:See above.
  • Pronouns:He / Him
  • Location:Ohio

Posted 07 July 2021 - 05:14 PM

The whole need for Waitframe() has always confused me. Does not having it mean that Demonlink's code snippet runs 120 times in a single frame instead of 1 time over 120 frames?



#4 Demonlink

Demonlink

    Lurking in the shadows...

  • Members
  • Real Name:Miguel
  • Location:Wouldn't you like to know?

Posted 07 July 2021 - 05:37 PM

You've got almost everything right here. The only issue is, like you pointed out, the for loop only runs for one frame. That's because scripts will do everything in a single frame unless you explicitly tell them to wait a frame. So all we have to do is take your while loop and add an instruction for it to do that.
 

                    for(int i = 120; i>0; i--){
                         Screen->FastCombo(7,0,0, COMPASS_VISUAL_CMB, COMPASS_VISUAL_CSET,OP_OPAQUE);
                         Waitframe();
                    }
 
Easy peasy. Now, for 120 times, it'll draw the combo, then wait for the next frame.
 

Thank you Russ! I'll test it tomorrow since I'm heading for work right now. :D


The whole need for Waitframe() has always confused me. Does not having it mean that Demonlink's code snippet runs 120 times in a single frame instead of 1 time over 120 frames?


I think it basically skips that line completely since there is no command for it to "wait until those 12 times" have happened.

#5 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 07 July 2021 - 06:23 PM

The whole need for Waitframe() has always confused me. Does not having it mean that Demonlink's code snippet runs 120 times in a single frame instead of 1 time over 120 frames?


That is exactly what it means, yeah. There's definitely times when you want that (such as looping over every combo on screen to check for something, for example), but this is not one of them.
  • Matthew likes this

#6 Mitchfork

Mitchfork

    no fun. not ever.

  • Contributors
  • Real Name:Mitch
  • Location:Alabama

Posted 08 July 2021 - 02:37 PM

FYI, I had a response to this thread and it got out of hand - please see this topic for an essay about Waitframe():

 

https://www.purezc.n...showtopic=77032


  • Matthew likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users