C
C#12mo ago
chronos

while loop freezes game?

moving this question to a new thread..
No description
55 Replies
daniel2
daniel212mo ago
Is the if statements inside a sort of timer_tick event?
Angius
Angius12mo ago
Why not just... do a thing on button press? As in, use the button click event?
chronos
chronosOP12mo 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
Omnissiah
Omnissiah12mo 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
chronosOP12mo ago
uhh im a bit of an idiot i dont know what that means cryglasses
Omnissiah
Omnissiah12mo ago
in what method is the loop in the image above?
chronos
chronosOP12mo ago
No description
chronos
chronosOP12mo ago
encounters class, and its in a method called Combat
Omnissiah
Omnissiah12mo ago
is it called from the form?
chronos
chronosOP12mo ago
and this is the form its running off of
No description
daniel2
daniel212mo ago
What u want to do when the button is pressed
chronos
chronosOP12mo ago
yes stop the loop and then play the equivalent action
Omnissiah
Omnissiah12mo ago
what is the loop doing?
chronos
chronosOP12mo ago
the loop does literally nothing
daniel2
daniel212mo ago
What is player
chronos
chronosOP12mo 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
Omnissiah
Omnissiah12mo ago
ah i thought you were talking about the main game loop
chronos
chronosOP12mo ago
No description
Omnissiah
Omnissiah12mo ago
you have just to move that stuff in its class add the data to the class to have a context
chronos
chronosOP12mo ago
this is what the code looks like for the buttons
Omnissiah
Omnissiah12mo ago
and then call that class from the button to continue with the next steps
chronos
chronosOP12mo ago
like i need to have a reference to Combat in the buttons..?
Omnissiah
Omnissiah12mo ago
you have to extract the logic create a class with the logic behind your game
chronos
chronosOP12mo ago
cuz the loop is perfectly able to read if the variable is TRUE but for some reason the freezing happens when its false
Omnissiah
Omnissiah12mo ago
yeah because it's blocking the program
chronos
chronosOP12mo 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
daniel212mo ago
What will happen when u click the button in terms of the game Yes
chronos
chronosOP12mo 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
daniel212mo ago
Thread.sleep stop entity program Entire
Omnissiah
Omnissiah12mo ago
you have to think that stuff happens when user does something
chronos
chronosOP12mo 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
Omnissiah
Omnissiah12mo ago
i know, but you shouldn't
daniel2
daniel212mo ago
Why do u want to stop the program? Is there any thing will constantly happen? Like animation?
chronos
chronosOP12mo ago
makes sense, how would i actually do that its just supposed to wait until the player makes an input, its turn based
Omnissiah
Omnissiah12mo 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
Angius12mo 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
daniel212mo ago
Make your damage enemy logic here
Angius
Angius12mo ago
You don't need to wait for input
chronos
chronosOP12mo 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
chronosOP12mo ago
(the loop that waits for input is beneath this)
No description
chronos
chronosOP12mo ago
i want to have it all in this specific class
chronos
chronosOP12mo ago
are you saying this should activate a new method or something
No description
chronos
chronosOP12mo ago
because if that was the case wouldnt it mess up the combat, i want it to keep looping until the battle ends
Angius
Angius12mo ago
I guess you could make a new form that represents the combat screen And have all the combat events there
chronos
chronosOP12mo ago
yes i could do that
Angius
Angius12mo ago
From the main screen, you would open that combat form when it's time to fight
chronos
chronosOP12mo ago
i would have to redo most of how the game looks and also re code everything though cryglasses
Omnissiah
Omnissiah12mo 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
chronosOP12mo 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
Angius12mo ago
You're also using Winforms
chronos
chronosOP12mo ago
yes less experience here...
Omnissiah
Omnissiah12mo ago
like the ancient ones
chronos
chronosOP12mo ago
its not my choice its for my college ffinal : p
Angius
Angius12mo 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
chronosOP12mo 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