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.

DarkBASIC Discussion / how to organize data printed to screen

Author
Message
anim8ed C4
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Jan 2010 20:25
hi im new to darkbasic and ive been given a project to make a program that stores the name and position of 6 characters using arrays. Ive finished the code, but im trying to get it where it prints out more organized. heres my code.

thanks
BCIT
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 27th Jan 2010 00:12
Why don't you try naming and generating random numbers in one loop

for example:



How are you storing the random numbers?

Should'nt you have code that looks something like:


TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Jan 2010 00:29
The command 'Text' is just like Print but a lot more flexible as you can supply an X/Y screen co-ord with it.

But, if you have to use Print for now, take a look at the Set Cursor command.

TDK

29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 27th Jan 2010 00:48
The only problem with using the text command is that it will only print strings to the screen not numbers.

This does not work



But this will



I tend to favour the print command for this reason.
Double B
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 27th Jan 2010 07:27
Quote: "The only problem with using the text command is that it will only print strings to the screen not numbers."

Yes, well, that's why there's STR$().
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 27th Jan 2010 14:06
Quote: "Yes, well, that's why there's STR$(). "


You're absolutely right but I would say it depends on what you're doing.

The "Set cursor" and "print" commands will work with anything without any further code but you don't get the same fine adjusment when printing to screen.

The "Text" command gives you the fine adjustment and easier placement if you're using other graphics but you need to add the extra command depending on whether the variable is a string or a number.

It depends what anim8ed C4 has been asked to do and where the bulk of the marks are. If the bulk of the marks are to do a some kind of calculation / data manipulation / storage and print values to screen, get that bit done first and then move onto the graphics.

We had a piece of course work on my mechanical engineering degree where people had spent a lot of time making nice intro screens but failed because their programs didn't do the calculations that were asked for. Had they've created the program where the user inputed the values, did the calculation and printed the answer all in the top left corner of the screen they would've passed.
Malboro Jones
14
Years of Service
User Offline
Joined: 10th Dec 2009
Location: Wales - UK
Posted: 27th Jan 2010 14:56
Use text or position cursor -


Good luck

Don't make war, make tea.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Jan 2010 18:29 Edited at: 27th Jan 2010 18:32
Just a note, the semi-colon after a print command tells print not to go to the next line so this:

would print

My name is Caleb

but this:

would print

My name is
Caleb

Just making sure you understand

New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Jan 2010 20:59 Edited at: 27th Jan 2010 21:11
Welcome to the forums Animated C4.

So you want to present this data in a clearer way?
I would display it in a table, but before I show you how to do that I'm going to have a look at your code and see if there are any improvements I can suggest.

It's a good idea to split your programs into three parts: The first part is where everything is initialised - this is where I would dimension all your arrays. The second part is where the real work is done; this section is often in the form of a loop that the program continues to run until the user exits the loop.
The final part is where everything is tidied up and deleted before ending the program. Since DB does a lot of cleaning up for you, you often wont need to have this clean-up section. You have used the END command which is good practice, when you start to use subroutines and functions you'll see why it is so important.

The basic process of your program as I understand is this:

From this diagram we can see two distinct parts of the main program. The first is the loop that gathers and stores the input and random values. The second part displays the data.
So here is what I have so far:

I put that "max" variable in so you can easily change how many characters you want the limit to be. See how now your end condition is in a loop it has a real effect. I've altered it so instead of ending the program it exits the loop and proceeds to the display section.

Now we've got everything done except the display. To arrange the data in a simple table we'd do something like this

The column positions are constant (0,100 and 180) for the different types of data, the interesting part is how the rows are positioned. We use the index number of the array to distinguish the characters from each other. 18 is the space (in pixels) from the top of one row to the top of the next - try changing this and see the spacings change - multiplying that by the index gives a nice ordered list.

Hope that helps.

PS I've made a fancier version that adjusts the width of the name column based on how long the names are.

If you have any questions just ask.

[edit]
Oops I just did someone's homework for them
I'll leave it here as I've spent about an hour on this thread but please don't just copy my code. I wrote this for you to learn from

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
BCIT
14
Years of Service
User Offline
Joined: 26th Jan 2010
Location:
Posted: 28th Jan 2010 01:36
Hi all,

Thanks for helping. I'm going to mention to the class again that you all are willing to help out and that is clearly evident.

Quote: "
I'll leave it here as I've spent about an hour on this thread but please don't just copy my code
"


Wow OBese87! I'll be sure to mention that to the class. That's ok that you did the homework, I want my students to want to come back to this board, especially if they know your here to do their homework for them ,
anim8ed C4
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 30th Jan 2010 05:07
hey i haven't checked in awhile, but thanks for everything i should now be able to finish up the project in no time. thanks again

Login to post a reply

Server time is: 2024-04-18 05:11:25
Your offset time is: 2024-04-18 05:11:25