Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Trouble with a loop

Author
Message
austin397
User Offline
Joined: 29th Oct 2020
Location:
Posted: 29th Oct 2020 02:35
For some reason, this loop is causing me issue's. If I take this part out everything works fine. I'm relatively new to AppGameKit so any help would be hugely appreciated!
smallg
Valued Member
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 29th Oct 2020 11:02
GetPointerState() doesn't update unless there is a Sync() and you won't see any changes on screen anyway unless there is a Sync() in the loop
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
Lupo4mica37
User Offline
Joined: 1st Jun 2020
Location:
Posted: 29th Oct 2020 23:51 Edited at: 31st Oct 2020 20:39
Hi Austin, just saw your code. Your rem "attack when mouse is clicked, but not while already attacking" and the relevant code for it, there is something not right about that logic.

If the mouse button is the input that decides between light or medium or heavy attack, then you if statement of "if GetSpriteCurrentFrame(HeroKnight) < AttackLightStart or GetSpriteCurrentFrame(HeroKnight) > AttackHeavyEnd", wil prevent the mouse button to be registered as it is within that if statement. Not knowing the entire logic of your code it is difficult to tell for sure where the problem is, but when input is the deciding factor, you want the first if statement to be "if GetPointerState() > 0". Try to reverse the order of things and reprogramme the logic of this if statement, and maybe change the while command to something more appropriate, or use more than one while command to account for the various states.

I hope that helps, please let me know on your progress.

All the best.

EDIT: I further pondered on your code, and actually for the logic you want "if GetPointerState() > 0" does not meet the requirements, you could include the following "if GetPointerState() > 0 and GetSpriteCurrentFrame(HeroKnight) < AttackLightStart or GetPointerState() > 0 and GetSpriteCurrentFrame(HeroKnight) > AttackHeavyEnd" and then follow with more if statements, as an example.

EDIT 2: Also depending on the logic, the order of the sequence of reading each line of code and if statements can be a factor for something working or not working, sometimes you need one if statement to be done, before the Sync() command and another after the Sync() and loop is complete. This Sync() is crucial to a lot of logic and what happens before one Sync() and after in the main loop, has consequence on how things happen. It's quiet interesting thing, experiment with it with different logic. For example:



Depending where you put the Print function and the order you put the if statements, you will get various results. When logic gets more complex, this things do make a lot of difference for something to work or not work.
????????
29 games
15
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 30th Oct 2020 18:12
In addition to Lupo$mica37's answer, the use of the a "while - endwhile" loop is incorrect and should be replace with an "if" statement.

In the original code the program will get stuck in the "while - endwhile" loop when the pointer is pressed and only come out of it once the player releases the pointer.

If the rest of the code is working then I'm guessing that the sync() command is called somewhere else so the getpointerstate() should be registered.

Login to post a reply

Server time is: 2021-04-14 09:21:18
Your offset time is: 2021-04-14 09:21:18