Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Loop Issue

Featured Replies

Hello

So this has been my issue for the past 6 hours and I cannot crack it so I have given in and come to where I know someone will know the answer. 

Anyway, basically I am using this section of code:

Spoiler

                    while (true)
                    {
                        if (Game.IsKeyDown(Keys.L))
                            LKeyPressed();

                        if (Game.IsKeyDown(Keys.K))
                            KKeyPressed();
                    }

However, when this code is carried out it freezes the game or takes the game to around 1 frame every 12-15 seconds (no exaggeration). This section of code isn't being carried out in a loop (hence that's why I made my own). But any help is much appreciated, thanks guys.

Edited by ScottehBoyy
Typo

ScottyTooHotty

First of all, make sure you run any looping code in a new fiber. Second, yield the fiber on every loop. 

GameFiber.StartNew(delegate{
	while (true)
	{
		GameFiber.Yield();

		if (Game.IsKeyDown(Keys.L))
			LKeyPressed();

		if (Game.IsKeyDown(Keys.K))
			KKeyPressed();
	}
});

 

[REL] Coastal Callouts: An action-packed mod with new vehicles, maps, capabilities, and callouts in and around the waters of Los Santos

[REL] Police Tape: Make your scenes more realistic while stopping peds and traffic

[REL] Better EMS: Realistic and dynamic EMS response

Join the Parks Benefactor Program to support my work and get early beta access!

If you're not already, wrap it in a GameFiber. If you are, then add a call to GameFiber.Yield(). Something like this should work:

 

GameFiber.StartNew(delegate {
	while(true) {
		if (Game.IsKeyDown(Keys.L))
			LKeyPressed();
		if (Game.IsKeyDown(Keys.K))
			KKeyPressed();
		GameFiber.Yield();
	}
});

 

My YouTube Channel: Darkmyre Gaming (Australian LSPDFR patrols, plugins in development, and other games)

My Discord Server | AusGamer Network

 

Please do not PM me for technical support or bug reports, use the appropriate forum or plugin's comments instead.

  • Author
10 hours ago, Darkmyre said:

If you're not already, wrap it in a GameFiber. If you are, then add a call to GameFiber.Yield(). Something like this should work:

 


GameFiber.StartNew(delegate {
	while(true) {
		if (Game.IsKeyDown(Keys.L))
			LKeyPressed();
		if (Game.IsKeyDown(Keys.K))
			KKeyPressed();
		GameFiber.Yield();
	}
});

 

Thanks guys, it was already in a GameFiber but there was no yield, thanks. @Darkmyre @PNWParksFan

ScottyTooHotty

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.