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 / Firsttimer question

Author
Message
PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 28th Aug 2005 18:57
Hello, i am trying to create a small game where "click me" randomly appears, and a point is given if the mouse is moved over it. However, my current version does not work (mouse stuff) and i do not know why. Any help appreciated



Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 29th Aug 2005 01:32 Edited at: 29th Aug 2005 01:44
use this


i took out the sleep command and put in a c#=10000 and dec c# in the loop because sleep goes past the mouseclick thing like a pause command and i took out the randomize command out of the loop so it won't always randomize and used sceen width and height so it wont go past the screen and people with different sized screens.I made go over the whole word using greater and less then symbols and every time it gets click or runs out of time it goes to the beginning and repositions the word and i used the inc command instead.Hope this helps.

NARUTO IS THE NINJA.....not really
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th Aug 2005 03:14
To build on Slayer93's example, try the code below.

I suggest that you NEVER ever use Goto. It is one of the worse habits you can get into when you start learning to program and very difficult to get out of.

There are ALWAYS alternative ways to do something instead of using Goto!

Enjoy!



If there's anything you don't understand, just ask...

TDK_Man

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 29th Aug 2005 20:49
Don't be so negative about goto's.

They can be VERY handy. For example:

Your game is finished and you want to display the player's score and buttons to replay, go back to the menu and to quit the game. This means you have to be able to go before the game loop to reset the game, or to go before the menu loop to display the menu.
Without goto you're nowhere...

Immunity and Annihalation makes Immunihalation...
PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 29th Aug 2005 20:49
slayer93, what exactly does dec do? is it the same as wait and sleep without the game pausing?

and TDK, you are a few steps ahead of me, to be honest i dont understand your code really

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 29th Aug 2005 21:07
Pres: If you type something into DB and press F1, you will be prompted with an explanation of the command. Dec is simly DECREASE.

MyVar = 5
Dec MyVar

Now MyVar = 4. You can also say

MyVar = 10
Dec MyVar,7

And so on. Adding in a DEC in a loop, will decrease the integer every loop, which is useful for timers and such.


Click here to join our forums and get updates on game progress sooner!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Aug 2005 01:29
Sven B

Quote: "Without goto you're nowhere..."


Rubbish!

Even what you described can be done quite simply without Gotos. I may be negative about the use of Goto, but for once, I know I'm right and I stand by what I say:

In a procedural language with Gosubs, functions and the many types of loops that DB has, there is no need to use Goto and if you can avoid them do so. Goto is a relic from the days when subroutines didn't exist and you had to use Goto 100 as there was no other choice.

They can cause problems too if used incorrectly. What happens to the stack if you continually use Goto to jump out of a For Next loop before it's finished?

Goto's can also mess up a compiler's optimization routines - leaving you with a slower program.

Even the scenario you described above, there's no need to use Goto to do it.

Your menu is a loop in a procedure which you Gosub at the start of the program. If exit is selected you end the program there and then and if Play is selected, you drop back out of the loop, return and drop into the main loop to play the game.

At the end of the game, you Gosub to the Hiscore table if required (another user-exited loop), which eventually returns you back to the main loop where you Gosub the Main Menu once more - sitting there until you exit or start the game again.

You have one main do loop in your program, but there's nothing stopping you from having others in procedures where you can just sit there until the user makes a choice before dropping back to where you came from.

It makes more sense to 'Return' to where you came from in an orderly fashion rather than unconditional jumping around your program.

OK, no-one can stop you using Goto - I'm just saying that it's bad practice to do so and that you can write your programs without if you are carefull. You should indeed avoid using it.

That's where the term spaghetti code comes from - use of the Goto statement!

http://www.qm-systems.com/goto.htm
http://en.wikipedia.org/wiki/Goto_(command)

However, at the end of the day, I can only offer you suggestions based on my own 25 years of programming experience and if people want to do it their way, that's fine by me - it's certainly not something important enough to be worth arguing about anyway...

TDK_Man

Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 30th Aug 2005 02:05
Quote: "However, at the end of the day, I can only offer you suggestions based on my own 25 years of programming experience and if people want to do it their way, that's fine by me - it's certainly not something important enough to be worth arguing about anyway...

TDK_Man"


*chuckles* If it weren't for the fact that my bf is also a programmer, and winces at the sight of a Goto, then that would be quite funny
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Aug 2005 06:42
I use goto because there was nowhere to return to it just went right to the loop after it went to the beginning.If there was somewhere to return to I would use gosub instead of writing 2 goto commands.

NARUTO IS THE NINJA.....not really
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 30th Aug 2005 06:54
disable escapekey : while escapekey()=0
endwhile

is a much better loop structure then do/loop

btw goto bites in any language for spaghetti coders.

if your high score table was in a function you could easily run the function when required without a goto statement.

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself 
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Aug 2005 17:13
Slayer93:

I didn't say it was easy - lol!

You just have to be carefull where you put your Gosubs, bearing in mind that they will 'return' to the very next line after the Gosub.

If this helps, here's a basic empty skeleton to use as a template for any decent sized project, (Note: not real code):



Splitting your program into lots of specific tasks means you can place each one into a procedure (or function) and call it.

If you then have a bug in the program with say the control of the enemies, you know exactly where to go to fix the problem - rather than scrolling through hundreds of lines of code searching...

And Indi's comments are also valid!

TDK_Man

CaMeRoN H
19
Years of Service
User Offline
Joined: 21st Aug 2005
Location: Who knows?
Posted: 30th Aug 2005 17:26
ok enough lol


Current Project: Stealth Operations: Release Date: September

Login to post a reply

Server time is: 2024-09-24 03:28:01
Your offset time is: 2024-09-24 03:28:01