2014-10-13 03:08:10

Hi all,
So, after solving my footstep sound issue, at least temporarily for testing purposes, how can I get key_pressed to increment the player position variable by 1 and hold the key down? Key_pressed only moves with one press of right arrow, like I'd expect. So hmm, let's try key_down, which should change the player position variable by one with the key held down and the footstep sound should play. Well, to my surprise, it doesn't. The player starts at 0, and holding the right arrow immediately whips the player to 40, which I set as the end of the test grid. How is it possible to get around this, especially for those of you who have running code, Q9 you can obviously walk and stuff, so I'm trying to create something like that.
I suppose you use timers for that? To learn, I'm using the language tutorial mainly to try to get to grips with arays for random enemy respawning on the grids later, and the BGT reffrence. When I need help and know the basics of BGT, I use the reffrence to look through and see which functions I'll need. Oh and asking here of course.

Yeah. Looks like I won't get this game done by Halloween haha. Maybe I'll release it on Christmas, a scairy game instead of what people would normally expect on Christmas. As for planning, well it is certainly no BK. More like my own version of Super Liam, with enemies being more random and more encounters than just having to deal with said random enemies.

2014-10-13 03:59:34

I'm assuming you've got a while loop going around and around as fast as it can.  Something like:
while(True) {
//check all the keys and move the player herre
}
Now, key down for a specific key can be thought of as a variable: when the key is down, it's true and when the key is up it's false.  The trick here is to only increment the player's position once per iteration and to put a delay at the end.  If you're not, that's the first place there might be a problem-the loop will be executing thousands of times a second, so that little tiny slice where you press the key is actually a lot.  Key press will only happen once until you release the key, but key down is always true if it's down.  So slow down the loop--it looks like you want the wait function.
Know that this isn't the best.  When this approach becomes cumbersome, we can talk.  There's better ways to factor out the game code so that you can do more, and the next problem you'll run into is that you can't wait on sounds.  If you can't get it working, you should consider putting the code somewhere.

My Blog
Twitter: @ajhicks1992

2014-10-13 04:02:49

Hi Orin.
Yes do key down since that checks to see if a key is being held down and use key pressed to check if a key was pressed once. I think you might need an array to have the player move one step or a few steps this should solve your problem.

Guitarman.
What has been created in the laws of nature holds true in the laws of magic as well. Where there is light, there is darkness,  and where there is life, there is also death.
Aerodyne: first of the wizard order

2014-10-13 16:07:23 (edited by stewie 2014-10-13 16:07:38)

His problem was that the player's position variable was being incremented thousands of times a second. You could use a wait() function, or you could check your results against a timer. A wait function will basically hault execution of the program however until the wait period end.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.