Jump to content
Sign in to follow this  
tanu1215

[Resolved] Getting key press multiple times

Recommended Posts

 public void ConversationHuman()
        {
            GameFiber.StartNew(delegate
            {
                Game.DisplaySubtitle("~w~Talk to the ~y~Caller", 6500);
                Game.DisplayHelp(("Press '~b~Y~w~' to advance in conversation"), 6500);

                check = ESwitchCheck.init;

                while (true)
                {
                    if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.init)
                    {
                        Game.DisplaySubtitle("Oh my poor booboo!", 6500);
                        check = ESwitchCheck.first;
                        GameFiber.Wait(500);

                        if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.first)
                        {
                            Game.DisplaySubtitle("They must be so scared!", 6500);
                            check = ESwitchCheck.finish;
                            GameFiber.Wait(500);

                            if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.finish)
                            {
                                Game.DisplaySubtitle("Please officer, you must find them!", 6500);
                                GameFiber.Wait(500);
                            }
                        }
                    }
                    
                    GameFiber.Yield();
                }
            });
        }

 

I have looked through the API development forum for an answer, and either I've missed it, or it doesn't exist.

This is a pretty simple problem, which I'm sure has a simple answer, but I cannot come up with it for the life of me for some odd reason.

I want to have a ped say dialogue to the player every time the 'Y' key is pressed.

While testing, I come up to the ped, press 'Y', and only the first phrase is said to me: "Oh my poor booboo!" (yes it sounds weird, but will make sense when callout is released)

I press 'Y' again, and the second phrase does not execute.

Help appreciated,
Thanks
 

Edited by tanu1215

Share this post


Link to post
Share on other sites

I think it is because you have put all of the if statements inside each other.

Because when it runs through the while loop the second time, your check equals ESwitchCheck.first and not ESwitchCheck.init. So it doesn't meet the 'criteria' and never reads the second if statement.

 

I'd suggest using an else-if statement if possible.

while (true)
{
	if (Game.IsKeyDown(System.Windows.Forms.Keys.Y))
	{			
		if (check == ESwitchCheck.init)
		{
			Game.DisplaySubtitle("Oh my poor booboo!", 6500);
			check = ESwitchCheck.first;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.first)
		{
			Game.DisplaySubtitle("They must be so scared!", 6500);
			check = ESwitchCheck.finish;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.finish)
		{
			Game.DisplaySubtitle("Please officer, you must find them!", 6500);
			GameFiber.Wait(500);
		}
		else
		{
		}
	}
}

 

I'm not sure if the last else is needed so I put it there just in case. And I added the very first if statement but you can get rid of that and check for key press in the other if's and else if's if you prefer.

Share this post


Link to post
Share on other sites
17 hours ago, Cosmo said:

I think it is because you have put all of the if statements inside each other.

Because when it runs through the while loop the second time, your check equals ESwitchCheck.first and not ESwitchCheck.init. So it doesn't meet the 'criteria' and never reads the second if statement.

 

I'd suggest using an else-if statement if possible.


while (true)
{
	if (Game.IsKeyDown(System.Windows.Forms.Keys.Y))
	{			
		if (check == ESwitchCheck.init)
		{
			Game.DisplaySubtitle("Oh my poor booboo!", 6500);
			check = ESwitchCheck.first;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.first)
		{
			Game.DisplaySubtitle("They must be so scared!", 6500);
			check = ESwitchCheck.finish;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.finish)
		{
			Game.DisplaySubtitle("Please officer, you must find them!", 6500);
			GameFiber.Wait(500);
		}
		else
		{
		}
	}
}

 

I'm not sure if the last else is needed so I put it there just in case. And I added the very first if statement but you can get rid of that and check for key press in the other if's and else if's if you prefer.

I ended up figuring this out a while after I made the post. I find it weird how I only find things out after I make posts about it haha.

Thanks a lot!

Edited by tanu1215

Share this post


Link to post
Share on other sites
On 1/16/2016 at 1:10 PM, Stealth22 said:

A little late to the party, but I use a Generic List of strings, and I just cycle through them. Much better than hardcoding it. :thumbsup:

Yep, I have started to do that :)

Share this post


Link to post
Share on other sites

How was this figured out?

On 1/7/2016 at 9:27 PM, tanu1215 said:

I ended up figuring this out a while after I made the post. I find it weird how I only find things out after I make posts about it haha.

Thanks a lot!

I'm getting errors with init first finish and Im unaware of how to write the e switch check variable

Edited by Markadaliah

Share this post


Link to post
Share on other sites
4 hours ago, Markadaliah said:

How was this figured out?

I'm getting errors with init first finish and Im unaware of how to write the e switch check variable

It's been a while. Post your code and I can try to help.

Share this post


Link to post
Share on other sites

{

            base.Process();
            GameFiber.StartNew(delegate
            {
                if (Game.LocalPlayer.Character.DistanceTo(CalloutPositionTrooperCar1) < 5f)
                {
                    Game.DisplaySubtitle("Please locate your ~r~Supervisor~w~ for briefing", 3000);
                    //GameFiber.Wait(400);

                    {
                        while (true)
                        {
                            if (Game.IsKeyDown(System.Windows.Forms.Keys.G))
                            {
                                break;
                            }
                            Game.DisplaySubtitle("Glad you all could make it", 6500);
                            //  GameFiber.Wait(500);
                            GameFiber.Yield();
                        }
                    }
                }

 

                {
                    while (true)
                    {
                        if (Game.IsKeyDown(System.Windows.Forms.Keys.G))
                        {
                            break;
                        }
                        Game.DisplaySubtitle("We are going to be running some traffic enforcement as part of a new San Andreas Highway System initiative to reduce traffic fatalities", 6500);
                    }
                }


            });
        
            }

[Spoiler/]

I want to drive up to the scene, and have it display the locate sergeant message, and then after that, I want to be able to hit Y when I am right next to the sergeant, and have him say multiple subtitles of things/ Just a new basic feature for me that I have not learned yet. Thank you for offering the help

Edited by Markadaliah

Share this post


Link to post
Share on other sites
9 hours ago, tanu1215 said:

It's been a while. Post your code and I can try to help.

I guess a lot of my issue is with the game fibers because as long as I have that is key down stuff in there it with the game fiber and the gamefiber.wait, it just freezes the game

Share this post


Link to post
Share on other sites
11 hours ago, Markadaliah said:

I guess a lot of my issue is with the game fibers because as long as I have that is key down stuff in there it with the game fiber and the gamefiber.wait, it just freezes the game

Sorry for the late response. So I don't really understand your code.. I am not sure why you are using two while loops? There should only be one. And Yes, you're probably crashing due to you not yielding the fibers.

By the way, those Eswitch things are called Enums, and im simply using them as flags.

So here is some pseudo - code for what you'd probably want:

 

boolean isSpeechComplete = false;

while(!isSpeechComplete)
{
    while(!Game.isKeyDown(Key.Y)

    {
    GameFiber.Yield();
    }

	SayFirstthing;
	GameFiber.Wait(1000);
	SaySecondThing;
	GameFiber.Wait(1000);
	SayLastThing:
    GameFiber.Wait(1000);
	isSpeechComplete = true;
}

 

This obviously wont work.. but it should hopefully give you a good idea of what you may want to do.

If you need some more help, let me know.

Share this post


Link to post
Share on other sites
2 hours ago, tanu1215 said:

Sorry for the late response. So I don't really understand your code.. I am not sure why you are using two while loops? There should only be one. And Yes, you're probably crashing due to you not yielding the fibers.

By the way, those Eswitch things are called Enums, and im simply using them as flags.

So here is some pseudo - code for what you'd probably want:

 


boolean isSpeechComplete = false;

while(!isSpeechComplete)
{
    while(!Game.isKeyDown(Key.Y)

    {
    GameFiber.Yield();
    }

	SayFirstthing;
	GameFiber.Wait(1000);
	SaySecondThing;
	GameFiber.Wait(1000);
	SayLastThing:
    GameFiber.Wait(1000);
	isSpeechComplete = true;
}

 

This obviously wont work.. but it should hopefully give you a good idea of what you may want to do.

If you need some more help, let me know.

Yeah sorry for my shit code, I have a lot of garbage trial crap going on. But thank you, seriously, thank you so much. I am trying this now.

 

Damn, so close man, thank you. I just have one or two issues here. I want it to say more and more so I guess I could add more lines. But the thing is, when I accept the callout, the texts starts without waiting for my to hit G, and it just continues to loop. How to I stop the loop so I can end the speech the SGT will be giving, and then he will escort them to a spot to to run radar.

   public override void Process()
        {

 

            base.Process();
            Boolean isSpeechComplete = false;

            while (!isSpeechComplete)
            {
                while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

                Game.DisplaySubtitle("Today we are going to run speed trap traffic enforcement");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("I will call out the speed, car, and car color of the individual you are to pull over");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("Fllow me to the spot where we will setup, turn your radios to channels 15");
                GameFiber.Wait(3000);
                isSpeechComplete = true;
            }
        }
       

        public override void End()
        {

[Spoiler/]

Edited by Markadaliah

Share this post


Link to post
Share on other sites
17 hours ago, Markadaliah said:

Yeah sorry for my shit code, I have a lot of garbage trial crap going on. But thank you, seriously, thank you so much. I am trying this now.

 

Damn, so close man, thank you. I just have one or two issues here. I want it to say more and more so I guess I could add more lines. But the thing is, when I accept the callout, the texts starts without waiting for my to hit G, and it just continues to loop. How to I stop the loop so I can end the speech the SGT will be giving, and then he will escort them to a spot to to run radar.

 

  Hide contents

 

   public override void Process()
        {

 

            base.Process();
            Boolean isSpeechComplete = false;

            while (!isSpeechComplete)
            {
                while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

                Game.DisplaySubtitle("Today we are going to run speed trap traffic enforcement");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("I will call out the speed, car, and car color of the individual you are to pull over");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("Fllow me to the spot where we will setup, turn your radios to channels 15");
                GameFiber.Wait(3000);
                isSpeechComplete = true;
            }
        }
       

        public override void End()
        {

[Spoiler/]

 

Try putting a '!' to denote false. 

 

while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

Should be

 

while (!Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }


So basically we're checking to see if the G key is not pressed. This will yield the fiber and basically wait until the G key is pressed, then it will continue to the speech.

And the loop should stop after the boolean is set to true. So after that while loop, put any code you need for your SGT. to walk to a point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×