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 DBPro Corner / Need help with for...next loop, and keypress detection functions

Author
Message
Gyrich
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Here, obviously.
Posted: 28th Dec 2005 08:54
Hello all,

Im working on a game, where an 8x8 grid of boxes will be drawn to the screen. there will be regular boxes and various kinds of bad boxes that need to be neutralized, all of which have different behaviors based on the type of box it is. the user will use the home row keys (8 keys: ASDFJKL;, 8 colums) to try and neutralized the bad boxes. On to my problem: im working on the function that will draw my 8x8 grid of boxes to the screen, and when run, the code only draws the first box at the starting position, although the execution does hang a bit, as though all 64 boxes are being drawn, before i can press ESC to get back to the source code.

You can see that in the MakeGrid() function, i have 2 for loops, the second of which is commented out. I created the second loop as a test to see if my coding structure was sound, because the first for malfunctions as described above. when i use the second for loop, the commented out one(and comment out the first one instead), all 64 boxes come up on screen as they should in the 8x8 grid formation. You can also see that I have 2 print commands in my first for loop of the MakeGrid() function. I added those in to see if the Grid(Counters).CellXPosition and Grid(Counters).CellYPosition values were getting changed as they should. When i run the code, the values for those 2 variables do not change, X value stays at 11, Y value stays at zero.

Lastly, at the bottom of my code you see a commented out KeyIsPressed function, obviously engineered to perform a task if the key is pressed. when run it detects the keypresses fine, but i need to know how to code it so that when a key is pressed the program only detects it once, meaning that if the user holds the key down, the program won't do repeated detections. No methods that I have tried work, if the key is held down, "hello world" is printed repeatedly.

Sorry for the long post, and thank you for your help.

Gyrich

DBPro User
PC: WinXP, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mn DDR400 RAM. Thank you for your help.
Big Man
19
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 28th Dec 2005 14:07
Quote: "Error obtaining Source Code, invalid ID. Sorry but I've given up.
"


That is what it says in the source box. try using


BM

Our aim is to keep the loo's clean, your aim can help.
Gyrich
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Here, obviously.
Posted: 28th Dec 2005 15:28 Edited at: 29th Dec 2005 09:10
Ack sorry, thought i was supposed to put coding in the "Code" section of the "post forum message" box.

One other thing I noticed that was wrong with my code (i think): you see that I have declared the variables cellxsize, cellysize, and cellzsize at the top of hte program (globally, or so i thought) and within the function MakeGrid(). That is because if i run the MakeGrid() function without the variables declared in it, the program doesn't even draw the first box to the screen, there are no visible boxes. Does DBPro use local/global variables, or am i doing something wrong?

Ok here's my code:



Thank you for your help

DBPro User
PC: WinXP, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mn DDR400 RAM. Thank you for your help.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Dec 2005 20:02
Quote: "Does DBPro use local/global variables, or am i doing something wrong?"


Yes it does... you just add "global" before any variable when you define it. Arrays are automatically global unless you specify "local". But that isn't the problem.

The reason it doesn't move is because you're using the data thats stored in the array... which is at zero. So everytime "counters" increases the data goes back to zero. I would use the second routine and add "Grid(Counters).CellXPosition = xpos" to change the data.


Gyrich
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Here, obviously.
Posted: 29th Dec 2005 06:01
Quote: "The reason it doesn't move is because you're using the data thats stored in the array... which is at zero. So everytime "counters" increases the data goes back to zero."


Why does the data go back to zero if im performing the operation:

Grid(Counters).CellXPosition = Grid(Counters).CellXPosition + 11

in every iteration of the loop? What in my code is making the value return to zero? is it the for...next loop at the top that sets the original values for the 64 array variables? and thank you all very much for taking the time to look at my post

DBPro User
PC: WinXP, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mn DDR400 RAM. Thank you for your help.

Login to post a reply

Server time is: 2024-09-24 11:29:37
Your offset time is: 2024-09-24 11:29:37