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