|
You last visited: Today at 14:15
Advertisement
C++ loop ohne While
Discussion on C++ loop ohne While within the C/C++ forum part of the Coders Den category.
04/17/2014, 12:58
|
#1
|
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
|
|
|
04/17/2014, 13:18
|
#2
|
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
|
|
|
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
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
|
|
|
04/17/2014, 13:26
|
#4
|
elite*gold: 1
Join Date: Feb 2012
Posts: 248
Received Thanks: 45
|
Quote:
Originally Posted by Actidnoide
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.
|
|
|
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?
|
|
|
04/17/2014, 13:42
|
#6
|
elite*gold: 1
Join Date: Feb 2012
Posts: 248
Received Thanks: 45
|
Quote:
Originally Posted by Actidnoide
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?
|
|
|
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
|
|
|
04/17/2014, 13:55
|
#8
|
elite*gold: 0
Join Date: Dec 2010
Posts: 1
Received Thanks: 0
|
Dx
ich has problem du...???
|
|
|
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?
|
|
|
04/17/2014, 17:44
|
#10
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
|
Quote:
Originally Posted by Padmak
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.
|
|
|
04/18/2014, 03:06
|
#11
|
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
|
Quote:
Oder plattformunabhängig: std::this_thread::sleep_for().
|
|
|
04/18/2014, 15:09
|
#12
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
|
Quote:
Originally Posted by Delinquenz
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.
|
|
|
04/18/2014, 15:40
|
#13
|
elite*gold: 0
Join Date: Oct 2008
Posts: 1,637
Received Thanks: 1,119
|
Quote:
Originally Posted by MrSm!th
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
);
|
|
|
04/18/2014, 16:09
|
#14
|
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..
|
|
|
04/18/2014, 21:39
|
#15
|
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?
|
|
|
 |
|
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.
|
|