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 / Help optimising code

Author
Message
Viper Dragon Games
17
Years of Service
User Offline
Joined: 22nd Apr 2007
Location: In front of my computer
Posted: 25th Oct 2007 21:28
hi I know I joined awhile ago but I never really messed with DBP or DBC at all.

well here is what I'm trying to do I'm making a hang man game but not to good at code and my code is well over 700 lines and was woundering
if there was any way to shorten it up im not good at functions plus please dont tell me to you a mouse button function cause i want no mouse in this game so here is my code please help if you can



ps please help me with getting rid of the goto it seem to slow down code i think
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Oct 2007 21:38 Edited at: 25th Oct 2007 21:39
1. Post with a meaningful title!

=========================================================
2. This:



Can be reduced to this:



============================================================
3. Because you do the above several times, you can do this. replace it with a function call:



and at the end of your code, add the function:



Try that for starters

Viper Dragon Games
17
Years of Service
User Offline
Joined: 22nd Apr 2007
Location: In front of my computer
Posted: 25th Oct 2007 22:05 Edited at: 21st Nov 2007 15:58
@BatVink
Thanks that took my code down from over 700+ lines to 523 lines wow big dif and im not being sarcastic.

@anyone that can still help
i was woundering if there was also any way to make my keyboard select movments into a function like the up arrow and etc. but where they will also go where i need them to say the x cordnate and y cordnate
if so please help me

ps.. all help is thankful alot..

<a href="http://www.clixsense.com/?2294091"><img src="http://www.clixsense.com/Ad/clixbanner1.gif" style="border: solid 1px;"></a>
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Oct 2007 05:05
Your code contains a number of major errors, but this is normal if you are learning to program. Things will improve with experience.

I will probably be criticized for saying this, but you really should go and read a few tutorials for beginners so you know what procedures and functions are and how to use them.

As Batvink showed you, they are probably the number one way to reduce the number of lines in your program.

A programmer with the knowledge gained from a few tutorials would probably write the exact same program 10 to 15 times smaller.

You could start here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Also, what you have written is generally classed as 'spaghetti code' as it jumps all over the place with the use of the Goto command. It's use can be dangerous unless you really know what you are doing and shouldn't be used apart from very exceptional cases - and even then there are ways to avoid using it at all.

Tutorials will show you better and more efficient ways of writing your programs.

Good luck!

TDK_Man

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Oct 2007 05:05
I don't understand what you are asking.

I can tell you that you want the learn the KEYSTATE command and you will want this in your code. It's big - but it WON'T slow your code down:




How do you use THAT? Like This:



Good Luck!

Login to post a reply

Server time is: 2024-09-27 08:34:11
Your offset time is: 2024-09-27 08:34:11