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 / Sorting algorithm for an Array

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Mar 2011 22:25
I have a sorting algorithm for an array in this book that sorts out the highscores in a game and puts them in order. Its a very simple affair but unfortunatley i just dont understand how it works (they way i sort things in my head is not the same way a computer does it, i just look at them and it all happens automatically without thinking, i dont seem to have an order to how i sort things i just do it) this is not helping me follow what the computer is trying to do and because of this i am struggling to find a solution to sorting numbers in descending order (which i presumed would be some sort of reverse way of sorting in ascending) and also sorting within a 2d array in which names are stored with the score.

Basically its for a guessing game (i am trying to learn about high score and arrays, and also saving data and reading it from a file so i decided to do it within a 'guessing game 1-100').
What i want to do is let the player enter their name, have their go, then decide whether to play again or view the highscores, if you view the highscores it reads from an array (which at the start is just "Empty" - 10 Guesses for the 'Top 10 Scores'. Then it decides where to put them based on lowest score at the top. Because i cant work out how it arranges an array high to low, i also cant figure out low to high and the book is just a little too vague for me to understand.
Can someone explain how sorting algorithms work (as if you were trying to explain it to a 5 year old please). Then how i might keep the name tied to the score.
I made a type called player made up of a string for 'name' and a 'guesses' for number of guesses. Then fed in some info into an array like so

So i think this is right in getting the name to match up with the score but i just cant get past sorting.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Mar 2011 22:35
Ok as well i will probably have to include this code too. Now as far as i know it should work but because its decending yet the High score array starts at 1, when it gets to 0 in the array which i dont want it to check, it sees that whatever you guessed will not be better than 0 but i dont think its placing it in position 1 for some reason. I dont know where this is going wrong because i cant explain what the hell i just wrote.

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Mar 2011 22:50 Edited at: 4th Mar 2011 23:41
If you just want to insert a score into the high score board, you don't really need to sort the array. You just need to find out which "slot" the score fits into.

You can loop through the array, comparing each value against the player score. Once you find a value that is lower than your players score, you insert the new score into the array, bumping all the other scores down. The last score in the array is lost.

DBPro has several commands for inserting new values into arrays, at the top, at the bottom, somewhere in between. Check the help files on arrays, lots of good info there.

If your scoreboard starts off with "Empty" and zero for all the scores, you will have to ignore any of those entries when you check to see if and where the new score should be inserted.

EDIT: From your code, it looks like you have a good idea of the concept. You can trim it down a lot with a few commands. I'll post some code in a bit.

EDIT FOR CODE: Here's some quick and dirty code that you might be able to adapt to your program. Obviously you will already know the player name and score, so you won't need to ask for either. I just included them to show it might work.



Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Mar 2011 09:58 Edited at: 5th Mar 2011 10:30
Thats great Rich, thanks. I had a good look at that and can follow it, i was just wondering though, how does it know not to overwrite each one that it is less than because on each iteration it would surely say "yep, its lower than that put it here" then on the next one it would say "hang on its lower than here too put it here" and so on, filling the array with the lowest score.

Also i know that is a better easier way of doing it but i am also looking to understand the more complex long way round of sorting arrays so that i get a better understanding of what its trying to do, the array insert at element is a nice command it seems, but i am not sure if that (or similar) exists at c++ level (which one day in many years i hope to look at) so if i understand how that works it might help (though i could be completely wrong )

Edit: Oh and does Array insert not add an extra 1 to the array therefore taking it to 11, so in order to stop the array getting out of control if you only ever wanted it to be 10 would you delete the end element? For example if i put these highscores into a save file and keep loading them up and playing this game eventually i could end up with an array that has thousands of elements even though its only the top 10 that is displayed. I have seen a Delete array at element command or something somwhere and persume this would do it, but id still like to know how to do it the long way round aswell, but just so you nkow i threw your code into the guessing game and tinkered a bit and it works perfectly for purpose. Now later on i am going to try saving the array to a file then reading back from it so the highscores remain what they were last time they were saved.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Mar 2011 12:30
Quote: " how does it know not to overwrite each one that it is less "


That is what the "exit" command is for - after finding the correct spot for the new score, the "exit" causes program execution to leave the FOR/NEXT loop.

Quote: " Oh and does Array insert not add an extra 1 to the array therefore taking it to 11"


Yes, it does. And deleting the last element would be a good way to stop the array from growing. But... If you only save the top ten scores, then your save file will never be any bigger than ten scores. Did you plan on writing each score/name to a file? If you do it manually, just write the top ten scores. If you use IanM's plugin to save the UDT array, then removing that 11th element after each scoreboard update would be the way to go.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Mar 2011 14:32
If you are using the array plug-in from my plug-in set, then you have a few alternatives.

1. Simply use the SORT ARRAY command to sort the score field in reverse order.

Just overwrite the lowest score with your new score, then call this command.

You can pretty much guarantee that this will be faster than any sort you can code yourself in DBPro, although I encourage you to also write your own sorts to discover how they work (loads of information on wikipedia on all sorts of sorts).

2. Find the place you would insert, and instead use the ROTATE ARRAY command to put the item into place.

Again, just overwrite the lowest score. Then you search from the bottom of the array upwards to find the insert point. Lastly, call the ROTATE ARRAY command with that value, the array size, and a 'shift' value of -1.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Mar 2011 16:07
Thanks guys, i think that is what i would be looking for and i agree, i do need to learn more about how it does it, so i will pop on wiki to see how sorting algorithms work and i will get this plug-in of yours IanM and see whats what. How would i install it? I have not installed any plugins except the darkAI, darkPhysics etc that came with the pack but they were just self loaders, i am not sure what to do with the zip on yours im afraid.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Mar 2011 16:14
Just unzip the file into your installation directory and everything should automatically go into the right places.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Mar 2011 16:36
Brilliant IanM thanks, ill do that now.

I have another little problem with this particular array. I am also (as ive mentioned before) trying to get it to save to a file when prompted then reload it up. I dont mind it only having the top 10 scores because thats all i want, once your off that list your gone for good, that doesnt bother me at this moment. Only problem is, is because i have the array set up as a user defined type 'Save Array FILENAME, ARRAY NAME(0)' now does not work as it doesnt work for user defined array types. So how do i combat this, do i just read and write file and use a for next loop to write the data to a file and read from it when i want to open it?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Mar 2011 16:51
That's why Rich suggested my plug-ins in the first place - DBPro cannot save out a UDT array directly to a file - you have to write the code to load/save the file yourself. My plug-ins can, but you have to use my file commands to do it.

Example of using my commands:


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Mar 2011 17:05 Edited at: 5th Mar 2011 17:16
Ahh thats great. So basically its almost the same as DBpros save array command only it works with uder defined array types. I love it. Only thing is i cant get it to work, and none of the code is turning blue so i wonder if i have installed it properly. I dragged the files straight over and merged them and copied the one or two files it asks you to copy over.

Okay i got it to recognise the code but now although it compiles it crashes instantly so im not sure where i have gone wrong, would it be something to do with me not checking if the file exists?


Once again, thanks Ian.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Mar 2011 19:48
Very simple test harness for load/save highscore table:


Enter a name of 'quit' to exit the program and save the high scores. Or change the program so that it is saved after updating it instead.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 5th Mar 2011 23:16 Edited at: 5th Mar 2011 23:33
Im just going to pop my code in here, its the full game, its a bit messy i know but its been written in stages as i was learning. Reason im doing this is its still not working and the help file doesnt seem to include anything regarding any of the new plugin that i have installed, so i am having difficulty understanding lines such as
If Open datafile to read (1, "Highscore.dat") = 1
As i am not sure the conditions that would make it 1.

Whenever i run the below code it instantly crashes on me. Also i had a look around the help file and cant find any of the new commands that have been added so its obvious that i installed the help files wrong, but all i did was open the zip, and extract the files to the DBpro folder that had those folders in them and clicked merge and one or two files it asked to replace i said yes.



Id just like to add aswell that running the code in your last post Ian also makes DB crash on me so i am definately doing something wrong somewhere.

More edits: Just like to add that now i can get the help to show up by pressing F1, for some reason i couldnt before but now i can and from what i see the 'if open datatype to read etc etc = 1' means a check for if it is already open but i think its crashing because the file doesnt exist yet im not sure how to make it exist using the new commands. As i said before if i type something in i can get the help on it to come up by pressing F1 but i cant get an overview of the commands under the help file because they are not there. So under file - commands, the old commands are there, non of the new ones from the plugin so i am not sure what commands have been added so to speak.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Mar 2011 23:56 Edited at: 6th Mar 2011 00:00
Many commands that are used like

if command() = 1 then XXXX

attempt to execute the command. If it works then it returns a 1, if it does not return a 1, then it didn't work. So

If open datafile to read (1, "Hiscore.dat") = 1

means "attempt to open a datafile named Hiscore.dat for reading and if successful return a 1". In this case, if the command does not succeed, it would return a 0.

Also - Ian's help files are not part of DBPro, but you should see a list of links at the bottom of each of his help pages, allowing you to navigate to the section menu, the main index, the command list, the commands menu and the main menu for his plugin.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Mar 2011 00:59
Ahh thats great, i thought i had installed them wrong or something.
Now as my other question, how come the above code snippet crashes?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Mar 2011 01:55
Crashes how? With a DBPro error message or a Windows error message?

If it's a windows message, then did you read and follow the instructions in my first post on the matrix1 plug-ins thread that starts 'If the DLLs fail to load, then you may need the files in the following download'?

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Mar 2011 09:59 Edited at: 6th Mar 2011 10:07
Sorry i should have been more specific. Its a DBpro crash. It says 'Dark Basic Pro Project Has Stopped Working'. Just after it says compilation sucessful then opens a window, then crashes.
I am on Vista 32.
I am going to look at your post again regards to the plugins and see whats what in there. Im sure ill get to the bottom of it soon

Edit: Ok i copied them over but unfortunately i already have them so that wasn't the issue.

2nd Edit: Im pretty sure its the code and not the .dll's as i tried your timer program with the blinking cursor (a couple of posts down from your original thread about the plug-in) and that works fine which i presume it wouldnt if the plug in was installed incorrectly.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Mar 2011 21:23 Edited at: 6th Mar 2011 21:46
Wow, that is some convoluted code. You've got some nasty recursion with functions calling functions. You even have an END inside a function.

The first error I get when I compile is that the function Save() doesn't exist. I'll keep looking at it though.

EDIT: Commenting out the call to Save() was enough to get the program running, so if you get a crash error, the problem might be somewhere else.

Also, your Highscore() function writes the score file, then reads it. So, if the first thing you do is look at the scoreboard, you've just overwritten the saved scores with all empty values. I'm thinking you planned to put the writing part in a Save() function, but never did it.

Further EDIT: after moving the save code to a seperate function, and using ARRAY DELETE ELEMENT to get rid of element 11, the code seems to work okay. But, as Ian says, that much recursion could be overloading the stack.

If you put your menu code in the main loop, and just call whatever functions you need from there, you can avoid most of the recursion.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Mar 2011 21:32
I didn't really spend too much time looking at the code, but with the amount of recursion I see in there (all completely unneeded IMO), it's very easy to exhaust the stack - I'd guess that's what is happening here.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Mar 2011 22:26 Edited at: 6th Mar 2011 22:31
Yeah i know, the code is very messy, i did say that before, however my problem did not lie in the code being messy, it still does work (it just got messy because i was adding stuff here there and everywhere to it), my point was that the only thing making it crash were the 2 new peices of code that save and or load from the array. Everything else is fine, its not perfect by a long shot but it does not crash the program.
Here is some amended code (silghtly neater and less convoluted) but it still crashes unless the

if open datafile to write(1, "Hiscore.dat") = 1
save array to datafile high(), 1
close datafile 1
else
Print "Highscore could not be saved"
endif

Is removed.



Now please remember that its not just this new plugin that i know nothing about i am not sure about anything regards to saving the files. I know what i want to do and i can take a guess at what that new code is doing but i am not sure how to make a check for if the file exists and if it doesnt then make it, then save to it using the new code, would i use DBPros original commands for making a new file? Would that work? Also i do not understand what exhausting the stack means.

Thanks for the help though guys, ill get through this
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Mar 2011 22:35 Edited at: 6th Mar 2011 22:45
One thing you might try to do is isolate the problem.

Does this compile and run on your system?



If it crashes with the "Dark Basic Pro Project Has Stopped Working" error, maybe it's a Vista permission to write thing? If so, you can try running DBPro as administrator.

By the way, the thing about the "stack" is when something like this happens...

function a calls function b which then calls function a, which calls function b, etc. etc. All this without a clean end to each function, and pretty soon there's too many "running" functions and the memory allocation for them runs out. You just need to have a clear end for each function.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 6th Mar 2011 22:46
Yeah that works. But when i copied Ians earlier code


That unfortunatley didnt work for me, so i presumed the problem lay in there. If this is not the case would it be something to do with where i am / or how i am putting this in


Perhaps the way i am sorting the array is messing up how it is stored. Maybe the save file is trying to save an array that is 11 large (0-10) and that insert at element is making it 12 so that would trip it up?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Mar 2011 23:50 Edited at: 6th Mar 2011 23:51
Well, if you save an array with 11 elements, then loading it back into a 10 element array would not work.

As I said, once I put the save code in its own function, and deleted that 11th element every time I added a new score, it works fine.

Here's my version of your code...



It still has way too much recursion, but it runs okay.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Mar 2011 08:54
The code you amended was my original code. I posted up a new neater version which im sure is slightly better. Not my last post but the one just before it. I cant see where i am going wrong because i am trying to fit the new bits into my new code which is slightly different. Everything i am doing seems right but obviously its not as its still not working. I just need someone to point out the line where it is all going wrong in my new version. I tried the delete element bit aswell and because i didnt know how to use it i tried every single possibility there could be including the one that has ended up in your amendment and it still didnt work, so i know thats not the problem.

If my new code is still very recursive do you have any tips as to how i may avoid this in future?

I will post my new attempt below before i put the delete element in and just tried to save it. Then below that i will put in my new amended code from what you put in your last post. Please ignore the old earlier code and look at the new stuff i did, the old code is still messy because thats the old code, i cleaned (well i think i cleaned) it up a little before adding all the new bits.

Old attempt after cleanup but without deleting the array.




Newest Code: after cleanup but also with deleted element.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 7th Mar 2011 14:14 Edited at: 7th Mar 2011 17:14
Okay, I'll just work with your Newest Code. It runs okay for me, no crash or error. BUT - in your main loop, the first thing you do is Getnumber().

Getnumber() calls Game().

Game() writes the scoreboard file, after the player gets a "top ten" score. This overwrites the previous set of scores from the last time the program was run. If this is your intent, then great. But if you want to save the scoreboard from previous runs, then you need to load in the high scores at the start of the current run.

Does your newest code still crash? What error?

On avoiding unwanted recursion - try to avoid having your functions call each other or themselves. Write your code in a "top down" fashion until you have a better grasp on how subroutines and functions affect program flow.

The functions in your code don't require any parameters, nor do they return any values, so you don't really need any functions in your program. All of your menu choices could be handled with if/then blocks, or a select/case block.

You might try flowcharting your program on paper before you write any code. For a small program, this can really help. Here's a REALLY simple flowchart of how you might want your game to execute.



Attachments

Login to view attachments
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Mar 2011 19:09
Excellent advice Rich and i see what you mean with the diagram, thanks for that. I will take that on board when i write something next, i think i was just trying to get a few too many steps ahead and having things flow in a different way whereas i should call the function to do its job, get out of the function and go back to the main game loop (is this right?). I will bare all this in mind when moving onto whatever i do. The newest code does still crash and im not sure why, it instantly comes up with a DB Pro has stopped working error, this is before the 'game' has even started so to speak, rather than half way through it.

I think with your advice i will be able to pull out a better version of this but only once i understand how that array and how saving and loading the array works.

Once again though, thank you for the help so far.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 7th Mar 2011 20:10 Edited at: 7th Mar 2011 20:14
Quote: "...it instantly comes up with a DB Pro has stopped working error"


This is puzzling to me as well, since your newest code runs fine on both WINXP and VISTA for me.

Quote: "...once i understand how that array and how saving and loading the array works."


I was going to mention (but I forgot) that Ian's file commands work a little bit differently than the stock DBPro file commands.

With DBPro, to write a file, you must first make sure that the file doesn't already exist. Trying to write to a file that already exists just doesn't work, you have to delete the original file first.

Ian's OPEN DATAFILE TO WRITE is better behaved, and will go ahead and open the file, even if it already exists. It truncates the file to zero size, essentially starting a new file for you.

He also has OPEN DATAFILE TO APPEND, which will let you add data to a file.

Oh, I also forgot to mention that you should make sure you have the latest versions of both DBPro and IanM's plugin.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Mar 2011 22:24
I have the latest DBpro and also Ians plugin but im glad to hear that Ians Open datafile to append is better than DB's original one. That rules out the possibility of me trying to open a file that does not exist.

I am wondering Rich, this may or may not help locate why i am crashing, but a short while ago you posted in someone elses thread regards to creating sound (from memblock) and another thread was referenced in which i found this code :



Just for a laugh i decided to try this code and copy pasted unaltered into my DB and it does not work, it comes up with the same instant crash. I am not sure that that should happen. It does run programs so its not like its crashing on everything which would lead me to believe something is corrupted. I am at a bit of a loss with this so i appreciate you helping me get to the bottom of it.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 7th Mar 2011 23:04
Maybe you should start by uninstalling and reinstalling DBPro.

Other than that, if you have some programs that crash, and some that run, I guess you could look for commonalities between the programs that crash. It sounds very frustrating!

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 7th Mar 2011 23:22 Edited at: 7th Mar 2011 23:26
Ha, yeah it is. I will have a go at reinstalling everything and see if that helps. The only way i can get my 'newest coded guessing game' to work is by removing everything to do with saving the array (the file opening stuff). It works fine right up to that point.

So for example with the file related stuff rem'ed out this works fine.

Remove the remstart and remend on either of the two bits i did and it wont run.

And thanks to your help i have been looking in the meantime for help on flowcharts and how to make use of them in excel etc so that i might create a better / more simple program with less mess. I found this as well which i will try and use to help me http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm#exercise4

I will post the results of me reinstalling DB and then i will rerun the code that i posted last in regards to the sound and i will also try my last guessing game attempt, because that should definately run.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 8th Mar 2011 20:42
Right quick update. I tried it on my windows 7 laptop and it worked fine with that new code in it. I also reinstalled everything on my vista machine and now it works fine so something somewhere along the way got corrupted. A very frustrating problem indeed but one that appears now to be solved. All that is left si to position the loading of the array file at the beginning somewhere so that it carries the scores over from game to game.

Many thanks all.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 9th Mar 2011 20:56
Spent a couple of days on this now and tried every combination of open file to append / if open file to append / open file to write etc etc etc etc etc and so on and so forth swapping and copying and pasting to try and make this code save the array, then load it up when the highscores are called for (or at the beginning of the game, anything really just so it saves the contents of the array) Being that i have tried every combination in every place i can think of im now at a stuck point where i cant get it to work yet there is nothing else my limited knowledge will allow me to try, there is only so much i can get from a help file. So someone once and for all set me straight, make this work and let me know why/how it does work.


The above code will not work (i have tried so many variations) but while it might seem glaringly obvious to yourself please note that i am not even an ex programmer from another language trying to get to grips with DB, i am a complete beginner to programming in general and therefore need a little tlc when explaining what im doing wrong or what im not understanding.

Many thanks.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Mar 2011 22:44 Edited at: 9th Mar 2011 23:37
You need to read in the high score data once, at the top of your program. This is separate from displaying the high score.

And you still have too many function calls going all over the place.

I'll write you a version that follows that flowchart, and post it in a bit.

Here's a version that only uses two functions, and is somewhat easier to follow. I kept the ARRAY INSERT and ARRAY DELETE commands, but IanM's sort is also a good option. If you compare and contrast our two solutions, you'll get an idea of the options available for common tasks, like getting input, etc.



IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Mar 2011 23:02
Always correct your indentation immediately.
You only need to load the highscore table from the file once - no need to do it every time you want to look at it.
You need to load the highscore table first INSTEAD of just initialising it as you were doing.
You only save when the highscore table changes, and always overwrite, never append.
You don't need to insert/delete from the array, or search for an insert point. You just need to keep it sorted, and if the new score is better than the worst score (which is ALWAYS last in the table), overwrite that worst score with the new one and re-sort.
Get rid of all of that recursion. Simply not needed.

Not pretty, but it works correctly:


Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 10th Mar 2011 21:40
Thank you so much guys, i have learned much from this. It all works perfectly and as i wanted it to. Its a shame my DB was corrupted at the start which caused more problems than i was looking for but since getting it working things are making a lot more sense.
I especially like some of the additions and changes to the code such as

Notched into the main loop. Its things like this that i know, i can follow and it all makes perfect sense but i would never in a million years think of doing, so i always go the long way round with everything. Maybe its because i am still new to programming or maybe its the way i work things out.

Something else i have learned is that i need to tidy things up a little. Ian you mentioned indentation but there is nothing i could do with that, its how it copy pastes from DB back and forth, i get all sorts of horrible errors where the cursor is positioned in completely the wrong place from where you are typing and magical gaps appear from nowhere as you write and code moves around the screen that once had massive gaps in it, this i know is a problem with the IDE, however maybe i could do more to neaten things up my end so i have to ask the following.

Are there any decent sites where i can find good programming practices (the ones i found are all very complicated to follow and because they are not written for beginners and also mostly c++ and or java so it makes it even more difficult to follow and apply to DB). Are there any places i can learn to cut down on the recursiveness as i am obviously still making rookie mistakes and going about the long way of doing things when i dont need to. I would just like to learn to do things better, neater, easier to follow and more condensed, i believe this will make me a better programmer and while i am very new i have no bad habits that cant be unlearned so its best to start now before i form hard to break bad habits. I really appreciate the help.

Login to post a reply

Server time is: 2024-11-16 19:22:44
Your offset time is: 2024-11-16 19:22:44