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 / Random Clickable Numbers Issues

Author
Message
Ninjazz
16
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 31st May 2008 15:31
Ok, so I'm still pretty new to DBPro, been reading quite a few tuts, and trying to make sense of as much as I can. Anyways, I'm not bothering to try to start out on the next big RPG, and not even really anything graphical for starters, mainly what I want to work on is a simple "game" that involves a window with 25 panels, and those 25 panels all have a number in the center of them.
The idea is to see how long it takes a person to click on the numbered panels, in order, from 1 to 25.
So I've been cracking away at this all night, and my brain is starting to putout little puffs of smoke here and there. I have yet to program in the buttons (kind of dreading that... 25 buttons, ugh) or the logic to make sure the player is clicking them in order, or the timer, for that matter... what I have right now is lined drawn to make up the panels, and an "engine" per-say that picks a random number between 1 and 25, and then prints it into the center of a button.
This is where my problem is though, and I want it fixed before I move on. When the program runs, it dumps the numbers out there, but leaves an empty panel sometimes, and has issues, and doesn't wait for the "wait key" event, and just closes. What am I doing wrong here?
My code is here: (I know, it's very amateur code, but I'm a newb. Ideas are welcomed)



Thanks,
Ninjazz
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 31st May 2008 21:51
First of all, and there's no easy way to say this, your lack of programming basics is turning a very simple exercise into a very long-winded one. But this is normal when first starting out, so don't worry too much about that.

With experience, you will automatically spot thing like the fact that:



can be replaced with:



More importantly though, despite the fact that you are correctly starting with something simple rather than a complicated project, the method you are using isn't really suited to what you are doing.

For displaying the random numbers side of things, you would be better off with an array which starts empty and is filled with numbers randomly - rather than one filled with 1 to 25 and chosen from randomly (as you have done).

You can then just use a simple nested loop to print out the 25 numbers straight from the array. The click and detect section would also be made much simpler with sprites too.

Unfortunately I have to go out now, but have go at doing the above. I'll be back later on if you need more help...

TDK_Man

Ninjazz
16
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 1st Jun 2008 04:48
Ah, thanks for that TDK man, I knew there had to be an easier way to do that array, rather than typing out the strings all manually. Try as I might, I simply could not think of it, so I just decided that for the sake of moving on, I would do it the way I knew how.
I've actually read the first several of your tuts and kinda forgot about the Str$() command.

So, random number into the array is all fine and good, but how do I keep it from picking the same number twice? That was the whole reason for me to decide on the variables being pre-programmed into the array in the first place.
For this I looked around in the forums a bit and found a suggestion by some one to pre-insert the strings, then pick one at random, print it, and delete it from the array, so that's my reason for doing things this way. I need unique numbers.

As for doing things with sprites for the panels, I assume you mean something along the lines of attach a small sprite to the mouse and then have the panels be sprites, then detect the collision between the mouse and the sprite? I think I can figure that much out, as well as the whole value checking part to make sure the value clicked is one higher than the previous, and the timer.
But for the sprites then, are you thinking of creating 25 panel sprites and then dropping them randomly into the array?

Sorry, I know I'm asking lots of questions, but this is stuff I really wanna know, and keep practicing.

Login to post a reply

Server time is: 2024-09-27 16:31:58
Your offset time is: 2024-09-27 16:31:58