Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 14:15

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ loop ohne While

Discussion on C++ loop ohne While within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Unreal <3's Avatar
 
elite*gold: 1
Join Date: Feb 2012
Posts: 248
Received Thanks: 45
C++ loop ohne While

Hey.
Hab folgendes Problem;
Versuche mich zurzeit an einem kleinen Konsolenspiel, jedoch hab ich das Problem, dass ich nicht aus dem While Loop rauskommen, jedoch einen infinite loop brauche, for funktionierte ebenfalls nicht.

Code:
int _tmain(int argc, _TCHAR* argv[])
	{
	thread StatsT(Stats);
	StatsT.join();
	
	cout << "test1" << endl;
	cout << "test2" << endl;
	hp +23;
	getchar();
	return 0;
}

void Stats()
	{
	for(;;)
		{
	system("cls");
	cout << "RPG\n\n";
	cout << "Level: " << lvl << endl;
	cout << "Aktuelle HP: " << hp << "/" << mhp << endl;
	cout << "Erfahrung: " << Exp << "/" << mexp << endl;
	cout << "Gold: " << cash << "$" << endl;
	cash++;
		}
	}
Das Problem ist halt, dass es aus dem Thread nicht mehr raus kommt, jedoch er weiter laufen muss, die Frage ist nun: Wie?

Mfg
Unreal <3 is offline  
Old 04/17/2014, 13:18   #2
 
Padmak's Avatar
 
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
Lass StatsT.join() weg, und bau in die Forschleife BITTE nen 1-ms-Sleep ein, plus gib dein Menü am besten erst dann neu aus, wenn sich einer der Werte verändert hat
Und schmeiß using namespace std; raus

Padmak
Padmak is offline  
Old 04/17/2014, 13:18   #3
 
elite*gold: 1391
Join Date: Apr 2014
Posts: 77
Received Thanks: 14
Fuer das Verlassen einer Loop gibt es 'break;'.

Quote:
Originally Posted by Unreal <3 View Post
Hey.
Das Problem ist halt, dass es aus dem Thread nicht mehr raus kommt, jedoch er weiter laufen muss, die Frage ist nun: Wie?

Mfg
Wenn der Thread beendet wird, laeuft das Programm in deinem Fall auch nicht weiter. Was genau moechtest du erreichen?

//edit: und da hilft man mal eine sekunde zu spaet
Actidnoide is offline  
Old 04/17/2014, 13:26   #4
 
Unreal <3's Avatar
 
elite*gold: 1
Join Date: Feb 2012
Posts: 248
Received Thanks: 45
Quote:
Originally Posted by Actidnoide View Post
Fuer das Verlassen einer Loop gibt es 'break;'.



Wenn der Thread beendet wird, laeuft das Programm in deinem Fall auch nicht weiter. Was genau moechtest du erreichen?

//edit: und da hilft man mal eine sekunde zu spaet
Will erreichen dass sich der Loop dauerhaft wiederholt, jedoch das Zeug da drüber weiterläuft, also;

Code:
int _tmain(int argc, _TCHAR* argv[])
	{
	thread StatsT(Stats);
	StatsT.join();
	
	cout << "test1" << endl;
	cout << "test2" << endl;
	hp +23;
	getchar();
	return 0;
}
Edit: Es war schon ein Sleep drinne, ist momentan aber draußen.
Unreal <3 is offline  
Old 04/17/2014, 13:32   #5
 
elite*gold: 1391
Join Date: Apr 2014
Posts: 77
Received Thanks: 14
Dann solltest du .join() nicht aufrufen. Damit wartest du naemlich auf die Beendigung des Threads

ausserdem
Code:
hp +23; // soll wohl eher 'hp += 23;' sein?
Actidnoide is offline  
Old 04/17/2014, 13:42   #6
 
Unreal <3's Avatar
 
elite*gold: 1
Join Date: Feb 2012
Posts: 248
Received Thanks: 45
Quote:
Originally Posted by Actidnoide View Post
Dann solltest du .join() nicht aufrufen. Damit wartest du naemlich auf die Beendigung des Threads

ausserdem
Code:
hp +23; // soll wohl eher 'hp += 23;' sein?
Was soll ich stadessen tun? Ich muss doch ebenfalls irgendwie den Thread laufen lassen, right?
Unreal <3 is offline  
Old 04/17/2014, 13:46   #7
 
elite*gold: 1391
Join Date: Apr 2014
Posts: 77
Received Thanks: 14


Beim Aufruf des Konstruktors von std::thread wird der Thread bereits gespawned. Kein weiterer Aufruf noetig
Actidnoide is offline  
Old 04/17/2014, 13:55   #8
 
elite*gold: 0
Join Date: Dec 2010
Posts: 1
Received Thanks: 0
Dx

ich has problem du...???
lo3o is offline  
Old 04/17/2014, 14:49   #9
 
elite*gold: 5
Join Date: Sep 2006
Posts: 385
Received Thanks: 218
Der Code compiliert nichteinmal. Wie sollen wir dir helfen, wenn du nicht funktionierenden Code postest?
Nightblizard is offline  
Old 04/17/2014, 17:44   #10


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Quote:
Originally Posted by Padmak View Post
Lass StatsT.join() weg, und bau in die Forschleife BITTE nen 1-ms-Sleep ein, plus gib dein Menü am besten erst dann neu aus, wenn sich einer der Werte verändert hat
Und schmeiß using namespace std; raus

Padmak
Sleep(0) reicht.
MrSm!th is offline  
Old 04/18/2014, 03:06   #11

 
Delinquenz's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
Quote:
Sleep(0) reicht.
Oder plattformunabhängig: std::this_thread::sleep_for().
Delinquenz is offline  
Old 04/18/2014, 15:09   #12


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Quote:
Originally Posted by Delinquenz View Post
Oder plattformunabhängig: std::this_thread::sleep_for().
Das war Pseudocode ;O Sleep(0) wäre unter Windows nicht gültig (ein Argument zu wenig), falls du dich auf die WinApi Funktion bezogen hast.

Dennoch Entschuldigung für die irreführende Schreibweise.
MrSm!th is offline  
Old 04/18/2014, 15:40   #13
 
Tyrar's Avatar
 
elite*gold: 0
Join Date: Oct 2008
Posts: 1,637
Received Thanks: 1,119
Quote:
Originally Posted by MrSm!th View Post
Das war Pseudocode ;O Sleep(0) wäre unter Windows nicht gültig (ein Argument zu wenig), falls du dich auf die WinApi Funktion bezogen hast.

Dennoch Entschuldigung für die irreführende Schreibweise.
MSDN sagt
Code:
VOID WINAPI Sleep(
  _In_  DWORD dwMilliseconds
);
Tyrar is offline  
Thanks
1 User
Old 04/18/2014, 16:09   #14


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Muss am Schlafmangel liegen..

Dennoch war es nicht auf die Windows Funktion bezogen


Irgendwie muss ich an SleepEx gedacht haben..
MrSm!th is offline  
Old 04/18/2014, 21:39   #15

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Statt Sleep(0); könnte man eigentlich auch SwitchToThread() bzw. std::this_thread::yield() verwenden. Hat Sleep(0); irgendwelche Vorteile?
snow is offline  
Reply


Similar Threads Similar Threads
Loop Bug
07/02/2013 - SRO Private Server - 2 Replies
Hi, Everytime when I have to go to the temple of jupiter trainplace starting from Hotan to Constantinople the bot stops and log show it: http://img594.imageshack.us/img594/6830/1s.png http://i.imgur.com/laayGnK.png
Cant loop db bot :\
10/09/2010 - SRO Private Server - 4 Replies
i back to play swsro and i download the new bot and crack it . i tried to loop but when the char gets to potion store it buys potions and than when it finish its stop and doesnt do nothing anyone know what to do? thanks sry for bad english :\
[Bot]Loop ?
06/25/2010 - SRO Private Server - 1 Replies
I been trying to set up the bot to loop where i grind, and it doesnt works! someone has any idea how to make the bot loop? thanks!
Agbot loop dosnt loop
10/18/2008 - Silkroad Online - 1 Replies
my agbot after i tele will go through the 20 sec wait then says in bot concle feature not available yet feature not available yet idk whats wrong
Bot + Loop
09/02/2008 - Silkroad Online - 3 Replies
Bot + Loop I'm having trouble I followed the loop guide with agdev everything went fine good loop no bugs, But If the bot uses teleport scroll it turns of and the walkscript doesn't turn ON So do you have to turn it on yourself or is it a bug? If it's a bug i will gladly hear a solution thanks



All times are GMT +1. The time now is 14:16.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.