Jump to content

Photo

[FFC] Press button to trigger secret


  • Please log in to reply
7 replies to this topic

#1 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 17 January 2010 - 07:53 AM

I would like a very simple script for something I want to do:

I am already using scripts to use L to talk to NPCs, and would like to also use L to examine objects. However, I would like to have another FFC script such that when the player walks up to the FFC and presses L, the temporary screen secret is triggered. Can that be done? Easily? Or is there another, script-less way to do so?

Thanks,
~MoscowModder


#2 Joe123

Joe123

    Retired

  • Members

Posted 17 January 2010 - 08:09 AM

CODE
ffc script LTrigger{
    void run(int d){
        while(Distance(Link->X,Link->Y,this->X,this->Y) > d || !Link->PressL) Waitframe();
        Screen->TriggerSecrets();
    }
}

D0 is how close you have to be to the ffc to trigger the secrets in pixels

#3 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 17 January 2010 - 08:22 AM

From the nearest edge or from the center? Would touching it be 16px or 0px or 8px?

Oh and by the way, thanks.

#4 Joe123

Joe123

    Retired

  • Members

Posted 17 January 2010 - 08:25 AM

From the centre, touching it would probably be 16 pixels but I dunno, it's a circle so it might not be what you want. Try that and see what you think, and I can write a better collision detection if you don't like it.

#5 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 17 January 2010 - 08:28 AM

It doesn't have to be perfectly touching, just within a few pixels. That will work.

#6 Joe123

Joe123

    Retired

  • Members

Posted 17 January 2010 - 08:51 AM

Well try it with a few different numbers and see if it's what you want then.

#7 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 17 January 2010 - 10:44 AM

Sorry for just popping in here, but I was just wondering... how does this script work?

I see the distance function (and I know how it works), but what if you wanted, say, Link to be touching the FFC. You would set 'd' as 16 (or whatever works). But, doesn't your script say that if Link is further away than preset distance 'd', or if Link is not pressing 'L', activate the script?

Or, do things in While loops act reverse... or something?

I'm not a scripting professional, yet, so feel free to tell me if I'm misunderstanding!


Oh, wait! The While loop will run always, preventing the Screen->TriggerSecrets(); snippet from being used. So it'll wait till Link is not further away than 'd', and he's "not not" pressing L... Oooh...

Man, Joe, you're good! I would'a never thought of that! Sorry for barging in! I'll leave now! ^^' lol

Edited by AgentLym, 17 January 2010 - 10:49 AM.


#8 Joe123

Joe123

    Retired

  • Members

Posted 17 January 2010 - 10:54 AM

When people start out, they usually write scripts more like this:
CODE
ffc script LTrigger{
    void run(int d){
        while(true){
            if(Distance(Link->X,Link->Y,this->X,this->Y) <= d && !Link->PressL){
                Screen->TriggerSecrets();
                Quit();
            }
            Waitframe();
        }
    }
}


Compared to my script,
CODE
ffc script LTrigger{
    void run(int d){
        while(Distance(Link->X,Link->Y,this->X,this->Y) > d || !Link->PressL) Waitframe();
        Screen->TriggerSecrets();
    }
}

you can see that it's just a little bit less neat really, the actual script works exactly the same.

If you look there's one subtle difference, which is (as you rightly recognised) that the logic inside the while loop in my script compared to that in the if check in the new script is indeed reversed.
The first script says this:
CODE
loop the following code{
    if link is within 'd' pixels of the ffc, and he presses l{
        trigger screen secrets
        stop script execution
    }
    continue to internal processing
}


And the second one says this:
CODE
while link ISNT within 'd' pixels of the ffc OR he DOESNT press l{
    continue to internal processing (so idle the script and have it do nothing)
}
trigger screen secrets

and obviously script execution stops here anyway because its the end of the script, so I don't have to call Quit();

If you think about the logic, the while loop and the if check are opposites.
There's no real reason to do it the second way rather than the first other than that it looks a bit neater.

EDIT:
Oh, I see you got it while I was writing my post. Well ok =P
QUOTE(AgentLym @ Jan 17 2010, 03:44 PM) View Post
Man, Joe, you're good!
icon_slycool.gif


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users