C
C#6mo ago
chronos

while loop freezes game?

moving this question to a new thread..
No description
55 Replies
daniel2
daniel26mo ago
Is the if statements inside a sort of timer_tick event?
Angius
Angius6mo ago
Why not just... do a thing on button press? As in, use the button click event?
chronos
chronos6mo ago
im trying to contain it all in a method called combat dont think so? clicking the button sets the button clicked value to true which is supposed to stop the loop but the combat interface wont even open when the loop exists at all implementing it with literally nothing in it instantly breaks the game.. update: if the buttonclick value is false immediately upon the loop starting, it passes through fine. but if it is true, everything freezes i have the buttons set up to update that value to True, but i cant actually press the buttons due to the freezing
WEIRD FLEX
WEIRD FLEX6mo ago
that's a really wrong way to do it you're not even calling DoEvents you should use a synchronization primitive if you are doing this in another thread if not, then the code is wrong, it's not working like you think it does but it's unclear from here
chronos
chronos6mo ago
uhh im a bit of an idiot i dont know what that means cryglasses
WEIRD FLEX
WEIRD FLEX6mo ago
in what method is the loop in the image above?
chronos
chronos6mo ago
No description
chronos
chronos6mo ago
encounters class, and its in a method called Combat
WEIRD FLEX
WEIRD FLEX6mo ago
is it called from the form?
chronos
chronos6mo ago
and this is the form its running off of
No description
daniel2
daniel26mo ago
What u want to do when the button is pressed
chronos
chronos6mo ago
yes stop the loop and then play the equivalent action
WEIRD FLEX
WEIRD FLEX6mo ago
what is the loop doing?
chronos
chronos6mo ago
the loop does literally nothing
daniel2
daniel26mo ago
What is player
chronos
chronos6mo ago
it just exists to wait until a button is pressed created to store a bunch of values stores the stats of the player as well as the bool for when buttons are selected
WEIRD FLEX
WEIRD FLEX6mo ago
ah i thought you were talking about the main game loop
chronos
chronos6mo ago
No description
WEIRD FLEX
WEIRD FLEX6mo ago
you have just to move that stuff in its class add the data to the class to have a context
chronos
chronos6mo ago
this is what the code looks like for the buttons
WEIRD FLEX
WEIRD FLEX6mo ago
and then call that class from the button to continue with the next steps
chronos
chronos6mo ago
like i need to have a reference to Combat in the buttons..?
WEIRD FLEX
WEIRD FLEX6mo ago
you have to extract the logic create a class with the logic behind your game
chronos
chronos6mo ago
cuz the loop is perfectly able to read if the variable is TRUE but for some reason the freezing happens when its false
WEIRD FLEX
WEIRD FLEX6mo ago
yeah because it's blocking the program
chronos
chronos6mo ago
ohh OHH I THINK IGET IT are you saying that it wont detect anything else as long as that while loop is running?
daniel2
daniel26mo ago
What will happen when u click the button in terms of the game Yes
chronos
chronos6mo ago
when the button is clicked it stops the loop and then will damage the enemy ok ok. so how do i fix that
daniel2
daniel26mo ago
Thread.sleep stop entity program Entire
WEIRD FLEX
WEIRD FLEX6mo ago
you have to think that stuff happens when user does something
chronos
chronos6mo ago
uhh wdym like i shouldnt try to detect it from a loop you mean? the reason i was doing it like that was so i could contain it all within the combat method
WEIRD FLEX
WEIRD FLEX6mo ago
i know, but you shouldn't
daniel2
daniel26mo ago
Why do u want to stop the program? Is there any thing will constantly happen? Like animation?
chronos
chronos6mo ago
makes sense, how would i actually do that its just supposed to wait until the player makes an input, its turn based
WEIRD FLEX
WEIRD FLEX6mo ago
you should save the state (the situation) of what you are doing somewhere then process this state with the correct action when the user does something, like clicking the button
Angius
Angius6mo ago
If it's turn-based, why do you need a loop...? Make it event-based Attach a handler to the click event Do something Click something else, do something else
daniel2
daniel26mo ago
Make your damage enemy logic here
Angius
Angius6mo ago
You don't need to wait for input
chronos
chronos6mo ago
ok ok im Processing here i know i can attach stuff to an event where the button is clicked ive been doing that but like. how would i encapsulate that within the Combat class gimme a sec
chronos
chronos6mo ago
(the loop that waits for input is beneath this)
No description
chronos
chronos6mo ago
i want to have it all in this specific class
chronos
chronos6mo ago
are you saying this should activate a new method or something
No description
chronos
chronos6mo ago
because if that was the case wouldnt it mess up the combat, i want it to keep looping until the battle ends
Angius
Angius6mo ago
I guess you could make a new form that represents the combat screen And have all the combat events there
chronos
chronos6mo ago
yes i could do that
Angius
Angius6mo ago
From the main screen, you would open that combat form when it's time to fight
chronos
chronos6mo ago
i would have to redo most of how the game looks and also re code everything though cryglasses
WEIRD FLEX
WEIRD FLEX6mo ago
it happens from time to time that's why we tend to create layers of code so that we move the less possible when reorganizing
chronos
chronos6mo ago
when i made this same program in a console app i could just wait for input with a console.readline so im not used to it being like this
Angius
Angius6mo ago
You're also using Winforms
chronos
chronos6mo ago
yes less experience here...
WEIRD FLEX
WEIRD FLEX6mo ago
like the ancient ones
chronos
chronos6mo ago
its not my choice its for my college ffinal : p
Angius
Angius6mo ago
Which is made to make "gray button click makes gray textbox data save into MS Access database" kind of software Not games So you're fighting an uphill battle
chronos
chronos6mo ago
yeah i know ive made much more complex stuff in actual game software this program is just Evil but thank you for your help i will try the separate form < 3 im gonna check out this video on turn based combat in a winsform app so i dont mess up once again i think!
Want results from more Discord servers?
Add your server
More Posts