
-----------------------------------
Flikerator
Sun Sep 11, 2005 3:25 pm

Array of record, inside record :?
-----------------------------------
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 

Rh, Lh, Armor, Spl1, Spl2, Acc : array 1 .. 1 of Equip

to

Rh, Lh, Armor, Spl1, Spl2, Acc : Equip

-----------------------------------
Flikerator
Sun Sep 11, 2005 4:16 pm


-----------------------------------
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;

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]
Sun Sep 11, 2005 4:21 pm


-----------------------------------
var mage : Char

mage.Rh.Name := "Light Sword"

Now, you can always just do this:
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 :o

*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:

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
Sun Sep 11, 2005 4:28 pm


-----------------------------------
Lolz thanks for the help anyways :P = )

-----------------------------------
Cervantes
Sun Sep 11, 2005 6:43 pm


-----------------------------------
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!  :x

-----------------------------------
Delos
Sun Sep 11, 2005 10:05 pm


-----------------------------------
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
Mon Sep 12, 2005 7:16 am


-----------------------------------
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 = (

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
Mon Sep 12, 2005 2:58 pm


-----------------------------------
There is a reason for everything. :)
