Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Array of record, inside record :?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Flikerator




PostPosted: Sun Sep 11, 2005 3:25 pm   Post subject: Array of record, inside record :?

code:
import GUI

type Equip :
    record
        Name : string
        Type : string
        Stat : int
    end record

type Char :
    record
        Name : string
        Pw : string
        Race : string
        Gender : string
        Lvl : int
        Xp, xp : int
        Hp, hp : int
        Vit : int
        Str : int
        Dex : int
        Int : int
        Wis : int
        Bgold, gold : int
        MstAxe, MstSwrd, MstMce, MstStf, MstAir, MstFire, MstCold, MstArc, MstArm : int
        Algn : int
        Item : array 1 .. 30 of string
        Rh, Lh, Armor, Spl1, Spl2, Acc : array 1 .. 1 of Equip
    end record


I know i could reduce the code, i know there is probably an easier way to do it, but this is what i need;

To declare the name, type, and stat of Rh.

It will be something confusing im sure.

EDIT - Change

code:
Rh, Lh, Armor, Spl1, Spl2, Acc : array 1 .. 1 of Equip


to

code:
Rh, Lh, Armor, Spl1, Spl2, Acc : Equip
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Sun Sep 11, 2005 4:16 pm   Post subject: (No subject)

By making all the equipment into a var and not an array, and by actually making a var for all of them (forgot that part) i have figured it out (took aboyt 10 seconds when i tried).

Anyways incase you want to know what it is add this;

code:
var Player : Char

Player.Rh.Name := "blue"
put Player.Rh.Name


How it works;

When making the var go to the mother variable which is Player. Now you've "selected" all the variables in the Player record. When you choose to declare Rh it is also a record. So it acts like a "mother" variable for the Equip record. So then you must choose which variable you want to change in Equip. So far you have Player.Rh

Choose a variable inside that record and you end up with;

Player.Rh.Name
Player.Rh.Type
Player.Rh.Stat

If say Stat was another record, you would need to put another . after it and then the varible you want to declare.

I hope I explained this clearly enough.
[Gandalf]




PostPosted: Sun Sep 11, 2005 4:21 pm   Post subject: (No subject)

code:
var mage : Char

mage.Rh.Name := "Light Sword"


Now, you can always just do this:
code:
type Char :
    record
        Name : string
        Pw : string
        Race : string
        Gender : string
        Lvl : int
        Xp, xp : int
        Hp, hp : int
        Vit : int
        Str : int
        Dex : int
        Int : int
        Wis : int
        Bgold, gold : int
        MstAxe, MstSwrd, MstMce, MstStf, MstAir, MstFire, MstCold, MstArc, MstArm : int
        Algn : int
        Item : array 1 .. 30 of string
        Rh, Lh, Armor, Spl1, Spl2, Acc :
            record
                Name : string
                Type : string
                Stat : int
            end record
    end record

var mage : Char

mage.Rh.Name := "Light Sword"
put mage.Rh.Name


*edit* I posted too late Surprised

*edit2* Though, if you are simply going to have a synonym to the type name as the variable, you can just make the record a variable in the first place:

code:
var Char :
    record
        Name : string
        Pw : string
        Race : string
        Gender : string
        Lvl : int
        Xp, xp : int
        Hp, hp : int
        Vit : int
        Str : int
        Dex : int
        Int : int
        Wis : int
        Bgold, gold : int
        MstAxe, MstSwrd, MstMce, MstStf, MstAir, MstFire, MstCold, MstArc, MstArm : int
        Algn : int
        Item : array 1 .. 30 of string
        Rh, Lh, Armor, Spl1, Spl2, Acc :
            record
                Name : string
                Type : string
                Stat : int
            end record
    end record

Char.Rh.Name := "Light Sword"
Flikerator




PostPosted: Sun Sep 11, 2005 4:28 pm   Post subject: (No subject)

Lolz thanks for the help anyways Razz = )
Cervantes




PostPosted: Sun Sep 11, 2005 6:43 pm   Post subject: (No subject)

Aah, you've just come across a the sub-record. How wonderful it must feel! Just wait, however, until you've gotten used to it. You'll take it for granted, soon enough. You'll delve deeper, then realize you can't go deeper. Flexibile arrays simply cannot co-exist with the record! Mad
Delos




PostPosted: Sun Sep 11, 2005 10:05 pm   Post subject: (No subject)

To clarify Cervantes there, flexy arrays can hold vicious spawn of records, but records cannot give birth to flexy arrays.

Why? I'll give you three guesses.
Flikerator




PostPosted: Mon Sep 12, 2005 7:16 am   Post subject: (No subject)

So flexible arrays can hold records, but records can't hold flexible arrays (non-turing computer)? If thats true then you won't be able to have flexible sub records and that makes me sad = (

Quote:
To clarify Cervantes there, flexy arrays can hold vicious spawn of records, but records cannot give birth to flexy arrays.

Why? I'll give you three guesses.


Im guessing thats a joke implying there is no reason?
Cervantes




PostPosted: Mon Sep 12, 2005 2:58 pm   Post subject: (No subject)

There is a reason for everything. Smile
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: