Computer Science Canada [Tutorial] Records |
Author: | Andy [ Tue Nov 25, 2003 1:10 pm ] | ||||||||||
Post subject: | [Tutorial] Records | ||||||||||
A record is a structure of data with the same name but different subscripts. Structures are not a necessity for any program, but it will make your source look much more pretty. If we were to create a database on each student in the school, we may need several arrays:
as you can see, this is very annoying, not mentioning confusing if u were to access the info on a student however, with records, this can be very easy
now that student Data is a type, you can declare an array of it
to call up each elements of the structure
another great thing about records is that you can copy an entire record into another for example
the structure of student(1) will now be the same as student(2) well thats about it. |
Author: | Dan [ Tue Nov 25, 2003 5:13 pm ] |
Post subject: | |
thanks for the tutorial and i know have been whonting some bits so i gusse i will give you some for this better then spamming |
Author: | AsianSensation [ Tue Nov 25, 2003 6:20 pm ] |
Post subject: | |
wow, dodge not spamming? Wait....I just saw a pig go flying across my window, wow, these things actually do happen. anyways, always try to use records. Unless you are so good that you won't ever get confused with codes and what they do, and can handle large multi-dimensional arrays with ease, then use records, they are great for organization. |
Author: | Andy [ Tue Nov 25, 2003 7:01 pm ] |
Post subject: | |
lol, dan got pissed, so i got scared... unlike some other disrespectful lil kids here... recursion is nxt |
Author: | Mazer [ Tue Nov 25, 2003 9:49 pm ] |
Post subject: | |
nice tutorial. you can't tell, but i'm clapping right now. here, have some bits |
Author: | Atma Weapon [ Mon Dec 08, 2003 1:40 am ] |
Post subject: | |
This tutorial has been extremely helpful. Take all my bits, with my thanks, |
Author: | junkpro11 [ Sun May 09, 2004 10:42 pm ] |
Post subject: | |
one question....if i want to store the input from the user for each category, like firstname i would use get firstname student(1).firstname:=firstname is this correct? if i want to make this into like a database, which allows users to create records....... do i use array 1..100 of studentdata (eg 100 students)? how do i write each student file according to student number....like 10023.t or 15246.t etc |
Author: | AsianSensation [ Mon May 10, 2004 2:22 pm ] | ||
Post subject: | |||
use intstr to manipulate strings of the file name if you want a specific text file to be the student number of that student. |
Author: | junkpro11 [ Mon May 10, 2004 10:06 pm ] | ||
Post subject: | |||
an error pops up saying "expression cannot be followed by a '.' " |
Author: | Tony [ Mon May 10, 2004 10:56 pm ] | ||
Post subject: | |||
i'd assume it's suppost to be
|
Author: | lee_Amilghty [ Wed May 26, 2004 10:14 am ] |
Post subject: | how to pass the record to procedure to procedure |
since the record is made up by array, how can i declare the variable in the procedure? i wanna the record can be used in a wider range? need help!!!! ~.~ |
Author: | AsianSensation [ Wed May 26, 2004 7:32 pm ] |
Post subject: | Re: how to pass the record to procedure to procedure |
lee_Amilghty wrote: since the record is made up by array, how can i declare the variable in the procedure?
i wanna the record can be used in a wider range? no, records are not made up of arrays. You can have an array of records, but doesn't mean it's made up of arrays. secondly, what do you mean using records in a wider range? if you want to pass record from procedure to procedure, it's best to just declare a global record, and have procedures and functions that changes it. That would be the easiest way. |
Author: | Omicron91 [ Mon Dec 20, 2004 5:54 pm ] | ||
Post subject: | |||
Weird, I was just takign a break from making a program that used types/records, to bad I didn't see this about three hours ago, oh well, it worked out. Not done though.
|
Author: | wtd [ Mon Dec 20, 2004 7:10 pm ] |
Post subject: | Re: how to pass the record to procedure to procedure |
AsianSensation wrote: if you want to pass record from procedure to procedure, it's best to just declare a global record, and have procedures and functions that changes it. That would be the easiest way.
No, it wouldn't. This is never a good idea. |
Author: | Andy [ Mon Dec 20, 2004 7:33 pm ] |
Post subject: | |
i think he means it would be easier |
Author: | wtd [ Mon Dec 20, 2004 7:43 pm ] |
Post subject: | |
dodge_tomahawk wrote: i think he means it would be easier
No, it isn't. It makes it much harder to make adjustments to a program. |
Author: | Andy [ Tue Dec 21, 2004 2:47 pm ] |
Post subject: | |
true, but much easier to program it rite the first time |
Author: | wtd [ Tue Dec 21, 2004 3:48 pm ] |
Post subject: | |
dodge_tomahawk wrote: true, but much easier to program it rite the first time
Doing things the wrong way is not a path to doing things the right way. It just reinforces bad habits, and makes it ultimately harder to adopt a correct approach to programming. |
Author: | Andy [ Tue Dec 21, 2004 3:53 pm ] |
Post subject: | |
its hard to start nailing oop if they have no basic tho... |
Author: | wtd [ Tue Dec 21, 2004 4:04 pm ] |
Post subject: | |
Object-oriented programming isn't even the issue here. Good, structured programming is. Before students even begin to think about object-oriented programming they have to understand the concept of an interface... the proverbial "black box". What you're suggesting is the roots of "spaghetti code". |
Author: | Andy [ Tue Dec 21, 2004 4:27 pm ] |
Post subject: | |
no what im trying to say is.. they may not understand the importance of passing it through as a parameter, and resulting the object instead of just making it global... |
Author: | wtd [ Tue Dec 21, 2004 4:43 pm ] |
Post subject: | |
So make them learn a bunch of bad habits so they can see the beauty of doing it the right way? I can get behind that, except that CS classes move slowly enough already, and it takes time to unlearn all of the bad habits. |
Author: | gnarky [ Thu Mar 17, 2005 9:47 am ] | ||
Post subject: | |||
Ok im pretty new at this.
A couple questions: It says that expression is not a variable when I try to run it. What does that mean? It highlights the second last line. Also, how do I make it so that a user inputs his/her own data without writing over someone else's. |
Author: | Andy [ Thu Mar 17, 2005 4:07 pm ] |
Post subject: | |
userData is a type... you stilll have to declare a variable like var user:userData |
Author: | Cervantes [ Thu Mar 17, 2005 4:14 pm ] | ||
Post subject: | |||
Or you could go
Depending on what you want to do with userData, that may or may not be better. Also, when you say user inputs his/her own data... do you mean on screen, or to a file, or something else? |
Author: | gnarky [ Thu Mar 17, 2005 5:51 pm ] | ||
Post subject: | |||
ok...Ive got what I want to do...But I know, somehow, someway, there's an easier was to do this. Something with arrays would probably make it easier. Hope you can help me out.
|
Author: | Cervantes [ Thu Mar 17, 2005 7:47 pm ] |
Post subject: | |
Just use one file, and use a for loop to get information for theentire array. Also, I would suggest using a flexible array here. Are you certain that there are 1400 users? Does that number ever change? If it does, you'll want to use a flexible array. Also, by using a flexible array, you could create a "Register" button, and when it's clicked, a new user is created. You could also make a "Delete Account" button. |
Author: | atrain [ Fri Mar 18, 2005 12:48 am ] |
Post subject: | |
Wow thanx so much for this tutorial... had i read it before, it could have helped me quite a bit... i only ended up with 3 arrays though.... |
Author: | Drake [ Wed Jun 22, 2005 3:56 pm ] | ||||
Post subject: | |||||
How can I get one record to extend another record? For example, I'm making an RPG and I want to make a Monster record with the names of every monster in it. And I want each of those names to extend to another record so that I'm only using two records for the entire list. Is it possible to have this happen? I thought it would be something like this:
Is it even possible to do this in as simple or a more simpler fashion? |
Author: | Cervantes [ Wed Jun 22, 2005 4:19 pm ] | ||||||
Post subject: | |||||||
Good question. It's possible. But let's look at what you've got first: You've made a variable that contains fields for health and mana etc. Then, you've made a variable for several monsters, with fields whose typeSpec is a variable. This is not allowed; we want the typeSpec to be a type. So, change the first line from
to
Should work nicely now. The other thing to think about is that you don't want to have to make variables for all the enemies in the game. A better way than what you've got there follows:
But, what would be even better is reading data in from a file, and using flexible arrays. I don't know how this RPG will work, but if it were to be a complex graphical RPG, I suggest making groups of monsters that are sorted by the map/level in which they appear and then by their x and y coordinates on the map. Then the individual monsters have their starting coordinates within the group. |
Author: | Drake [ Wed Jun 22, 2005 5:01 pm ] |
Post subject: | Thanks! I'll use them both. |
Using the array, although not what I want to use, would probably work better for me. This would be due to the fact that random monsters will be poping up instead of pre-placed monsters. If I use the array then I can just get a random number for the monsters and be done with it. Or if I want to pick a specific monster just choose that number. Now all I have to do is to figure out how to do the darn battle system... |