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 / Multi-Dimensional Array with Data Statements

Author
Message
Davido01
14
Years of Service
User Offline
Joined: 28th Oct 2009
Location:
Posted: 28th Oct 2009 14:25
Hi, just wondering what is wrong with one of my programs I am doing from a tutorial. I think the problem is with the setting of the array but I am not sure.

Here it is:


The REM at the top of the code tells you what I am trying to achieve, but I am getting stuck just on the drawing of the squares.

Any help much appreciated.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Oct 2009 22:48
The problem is the tutorial itself.

DATA should always be at the end of the code, it should be read all at once if you're using an array, never, ever use GOTO, and KEYSTATE() is better to use than INKEY$(). KEYSTATE() allows us to hit multiple keys at once... you may not want that now but later you'll get annoyed using INKEY$().

Here's a link to my Keystate Map:
http://mysite.verizon.net/grueslayer/Keystate.png



TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Oct 2009 23:03
I agree with Grog - the tutorial you are using is dubious to say the least - it's teaching you very bad habits which will be hard to shake off.

Data statements, as Grog says, should be at the end of your program, but that's only a programming 'convention' - they will work anywhere. But conventions are conventions for a very good reason.

Try the tutorials here:

Programming Tutorials For Beginners

...in particular the 4-part series at the start.

TDK

Davido01
14
Years of Service
User Offline
Joined: 28th Oct 2009
Location:
Posted: 29th Oct 2009 00:04 Edited at: 29th Oct 2009 01:12
Thanks for the help. Used your nice keystate table to put keystates in and eventually worked out how to do the thing asked of me.



Wasn't quite sure what you meant by the GOTO problem though, so could you explain that a little bit more in detail please. Will look at your tutorials later TDK, and will stop using the tutorial that I am using now lol.

EDIT: Sorry didn't see your code snippet there, that is why I posted my version down with some tweaks. Can see how you get away with not using the GOTOs now.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Oct 2009 18:03
Quote: "Wasn't quite sure what you meant by the GOTO problem though, so could you explain that a little bit more in detail please.

EDIT: Sorry didn't see your code snippet there, that is why I posted my version down with some tweaks. Can see how you get away with not using the GOTOs now."


The main problem with GOTO is that it creates what we call Spaghetti Code (click on my signature to see the Wiki entry)... a jumbled up mess of code that's hard to track what's going on and debugging is a lot harder. GOTO forces you to use another GOTO to get back to the line you left. A better replacement is GOSUB. When you use GOSUB and you want go back to the line that sent you there use RETURN.

Your code with some changes using GOSUB instead of GOTO (with indenting to make it easier to read):


Another replacement for GOTO are functions. They are the same as using GOSUB except they don't keep variables that aren't set as GLOBAL. Functions are nice to use because they can be sent specific variables/strings and return a variable/string too.

Your code with some changes using a function:


The way I believe is that we should learn about GOTO when we're newbies but after we learn about GOSUB and functions we should leave GOTO behind and never use it again.

Quote: "Will look at your tutorials later TDK, and will stop using the tutorial that I am using now lol."


Yeah, TDK's tutorials are top notch... read them all even if you think you know everything about a command.

Login to post a reply

Server time is: 2024-09-28 12:16:14
Your offset time is: 2024-09-28 12:16:14