From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e55245590c829bef,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Beginners question: Compound types, how-to? Date: Sun, 31 Oct 2010 23:00:52 +0100 Message-ID: <86wroy58ff.fsf@gareth.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net J4dlsEDdl+RLad++ec9PLgzy4i0DX5CMlbPrJvVnpyEbG094rs X-Orig-Path: gareth.avalon.lan!not-for-mail Cancel-Lock: sha1:BqJ72NEzlUXI18xrN+VTrK9q45k= sha1:GBP0moNl6yw1TO9wnGchlJJJKwA= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Xref: g2news2.google.com comp.lang.ada:16047 Date: 2010-10-31T23:00:52+01:00 List-Id: Hi, I've been playing around with Ada for a bit, and like it. To teach it to myself, I am rewriting some Perl code I wrote for hobby purposes, yet I can't seem to get my head around how to use compound types. I have the following code (yes, I'm an RPG geek, sorry): games-rpg-dnd.ads: --with Games.RPG; -- Ignore parent package for now, we don't need the -- utility functions yet. package Games.RPG.DnD is type Ability_Type is (Str, Dex, Con, Int, Wis, Cha); type Ability is record Score : Natural; Modifier : Integer; end record; type Ability_Array is array (Ability_Type) of Ability; type Character is record Abilities : Ability_Array; end record; end Games.RPG.DnD; test-game.adb: with Games.RPG.DnD, Ada.Text_IO, Ada.Integer_Text_IO; use Games.RPG.DnD, Ada.Text_IO, Ada.Integer_Text_IO; procedure Test_Game is C : Character; begin C.Abilities(Str) := (Score => 10, Modifier => -1); Put (C.Abilities(Str).Score); put (C.Abilities(Str).Modifier); end Test_Game; When I do it like this: with Games.RPG.DnD, Ada.Text_IO, Ada.Integer_Text_IO; use Games.RPG.DnD, Ada.Text_IO, Ada.Integer_Text_IO; procedure Test_Game is A : Ability_Array; begin A(Str) := (Score => 10, Modifier => -1); Put (A(Str).Score); put (A(Str).Modifier); end Test_Game; It works, when I use the former code, it bombs with 'Invalid prefix in selected component "C"'; What am I doing wrong? I am misunderstanding something, but what? C should be a record containing an Ability_Array as its first field, so I should be able to index into it using an Ability_Type subscript. How do I do this? Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.