Coding layout problem
BlitzPlus Forums/BlitzPlus Beginners Area/Coding layout problem
| ||
I am new to blitzplus, and I don't know much about it. That's why I was wondering why people put certain code at different spots on the page... It's kind of hard to explain, so I copied a random piece of code from the beginner's tutorial to demonstrate. If iScore>0 Then Text 200,200, "Score = "+iScore Else Text 200,200, "No Score Yet!" EndIf Notice how the commands text 200,200 and so on are not completely on the left side of the screen, while some are? I don't know if you have to do this with certain commands, or yea... I'm really stuck here, and I would appreciate it if someone could tell a newbie a bit about this. Thanks! |
| ||
I don't know what happened, but the code went all to the left again! I hope you still get what I mean by all this. |
| ||
you can use "code tags" to get codeboxes like this:If iScore>0 Then Text 200,200, "Score = "+iScore Else Text 200,200, "No Score Yet!" EndIf Set one tag at the beginning of the code. The other on the end. All possible forum codes are here: http://www.blitzbasic.com/faq/faq_entry.php?id=2 use.... [code][/code] ...for a box, which show the whole length of code. Write your code between the both tags. Use... [codebox][/codebox] ...for a box, where the user can scroll through the code. |
| ||
To help answer the original question, and I'm no expert some of the words I'm going to use may not be correct. the computer doesn't care if all the lines start at the left of the screen. many programmers tab out the code so it's easier to read. If I was going to write a piece of code like this I'd probably write the first line with the IF command in it, then press enter a few times to make some space, then write the EndIf. Then go back to fill in the stuff in between. Now if that stuff in between is all tabbed in it's a lot easier to see what's going on. It gets even more helpful if you have another If command inside the first which will be tabbed out even more. I hope that helps a little, I'm new to this myself. Maybe a more experienced programmer will be able to explain it better. |
| ||
Alright, I think I've got it. |
| ||
Hello. I believe that the formal name of what you're referring to is "indentation," and it is a practice that serves no purpose other than helping the reader to better understand the scope and causality in a piece of code. http://www.cs.arizona.edu/~mccann/indent_c.html#One |
| ||
Yeah, indentation. It makes your code logic more readable. If you're not into the habit, get into the habit. It'll save you hours of pain in the future. Example: If something = True X = X + 1 A = 5 For n = 1 to 10 Print n Next Else Print "poop" EndIf Same code, indented: If something = True 'everything indented below happens if something = true X = X + 1 A = 5 For n = 1 to 10 'everything further indented happens during this For/Next loop Print n Next Else Print "poop" 'this only happens if "something" is anything other than True (i.e. False) EndIf |