comp.lang.ada
 help / color / mirror / Atom feed
From: Mart van de Wege <mvdwege@mail.com>
Subject: Beginners question: Compound types, how-to?
Date: Sun, 31 Oct 2010 23:00:52 +0100
Date: 2010-10-31T23:00:52+01:00	[thread overview]
Message-ID: <86wroy58ff.fsf@gareth.avalon.lan> (raw)

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.



             reply	other threads:[~2010-10-31 22:00 UTC|newest]

Thread overview: 190+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-31 22:00 Mart van de Wege [this message]
2010-10-31 22:36 ` Beginners question: Compound types, how-to? Vinzent Hoefler
2010-10-31 23:27   ` Yannick Duchêne (Hibou57)
2010-11-01  7:14     ` Mart van de Wege
2010-11-01 19:22       ` Jeffrey Carter
2010-11-02  9:38     ` J-P. Rosen
2010-11-01  3:55 ` Jeffrey Carter
2010-11-01  7:12   ` Mart van de Wege
2010-11-01 15:04     ` Shark8
2010-11-01 17:06       ` Mart van de Wege
2010-11-01 17:39         ` Yannick Duchêne (Hibou57)
2010-11-01 17:58           ` Mart van de Wege
2010-11-01 19:19         ` Jeffrey Carter
2010-11-01 19:41           ` Yannick Duchêne (Hibou57)
2010-11-01 20:56             ` Jeffrey Carter
2010-11-01 21:05               ` Yannick Duchêne (Hibou57)
2010-11-03 16:56             ` Warren
2010-11-03 17:01               ` Georg Bauhaus
2010-11-03 17:42                 ` Vinzent Hoefler
2010-11-04  5:23                   ` Stephen Leake
2010-11-04  9:41                     ` Georg Bauhaus
2010-11-06 16:49                       ` Stephen Leake
2010-11-06 18:43                         ` Jeffrey Carter
2010-11-06 19:35                         ` Georg Bauhaus
2010-11-12 20:17                       ` Randy Brukardt
2010-11-12 21:25                         ` Jeffrey Carter
2010-11-04 10:09                     ` Georg Bauhaus
2010-11-06 16:53                       ` Stephen Leake
2010-11-06 19:24                         ` Georg Bauhaus
2010-11-04 17:46                     ` Jeffrey Carter
2010-11-03 20:38                 ` Warren
2010-11-03 20:50                   ` Yannick Duchêne (Hibou57)
2010-11-03 22:32                   ` Georg Bauhaus
2010-11-04 13:59                     ` Warren
2010-11-04 20:57                       ` Martin
2010-11-05 20:43                         ` Warren
2010-11-03 20:44                 ` Yannick Duchêne (Hibou57)
2010-11-03 20:45                   ` Yannick Duchêne (Hibou57)
2010-11-03 21:27                   ` Simon Wright
2010-11-03 22:44                   ` Georg Bauhaus
2010-11-04  1:19                     ` Yannick Duchêne (Hibou57)
2010-11-04  5:18                       ` Shark8
2010-11-04  6:30                         ` Yannick Duchêne (Hibou57)
2010-11-04 14:23                           ` Warren
2010-11-04 10:29                       ` Georg Bauhaus
2010-11-04 11:06                         ` Yannick Duchêne (Hibou57)
2010-11-04 12:56                           ` Georg Bauhaus
2010-11-01 19:59           ` Shark8
2010-11-01 20:43             ` Yannick Duchêne (Hibou57)
2010-11-01 21:54               ` Shark8
2010-11-01 21:01             ` Jeffrey Carter
2010-11-01 21:49               ` Shark8
2010-11-02  0:07           ` Adam Beneschan
2010-11-02  8:17           ` Stephen Leake
2010-11-02  8:29             ` Yannick Duchêne (Hibou57)
2010-11-02  8:50               ` Dmitry A. Kazakov
2010-11-03 12:02               ` Searching for "_Type" discussions Stephen Leake
2010-11-02 19:02             ` Beginners question: Compound types, how-to? Jeffrey Carter
2010-11-02 19:22               ` Yannick Duchêne (Hibou57)
2010-11-02 20:24                 ` Simon Wright
2010-11-03 12:14                   ` _Type vs no _Type Stephen Leake
2010-11-03 21:16                     ` Yannick Duchêne (Hibou57)
2010-11-03 21:19                       ` Yannick Duchêne (Hibou57)
2010-11-04  5:37                         ` Stephen Leake
2010-11-04  5:29                       ` Stephen Leake
2010-11-03 21:29                     ` Simon Wright
2010-11-04  5:28                       ` Nasser M. Abbasi
2010-11-04  6:06                         ` Yannick Duchêne (Hibou57)
2010-11-04  6:40                         ` Shark8
2010-11-05 17:49                           ` Florian Weimer
2010-11-05 18:18                             ` Georg Bauhaus
2010-11-04 18:29                         ` Britt Snodgrass
2010-11-04 19:08                           ` Nasser M. Abbasi
2010-11-04 19:47                             ` Britt Snodgrass
2010-11-04 19:59                             ` Simon Wright
2010-11-04 22:38                               ` Yannick Duchêne (Hibou57)
2010-11-05  7:05                               ` Florian Weimer
2010-11-05  8:48                                 ` Yannick Duchêne (Hibou57)
2010-11-05 16:01                                   ` Dmitry A. Kazakov
2010-11-05 19:26                                     ` Jeffrey Carter
2010-11-05 19:34                                       ` Dmitry A. Kazakov
2010-11-05 19:35                                       ` Florian Weimer
2010-11-05 20:08                                         ` Dmitry A. Kazakov
2010-11-05 20:14                                           ` Florian Weimer
2010-11-05 21:01                                             ` Dmitry A. Kazakov
2010-11-05 20:45                                         ` Warren
2010-11-05 22:59                                           ` Brian Drummond
2010-11-09 20:29                                             ` Warren
2010-11-05 21:37                                         ` Jeffrey Carter
2010-11-05  3:10                             ` Georg Bauhaus
2010-11-05  6:54                             ` J-P. Rosen
2010-11-05 16:39                               ` Robert A Duff
2010-11-05 23:32                                 ` J-P. Rosen
2010-11-06  0:55                                   ` Yannick Duchêne (Hibou57)
2010-11-06 13:40                                     ` Simon Wright
2010-11-05 17:29                             ` Robert A Duff
2010-11-05 19:28                               ` Jeffrey Carter
2010-11-05 23:09                                 ` Robert A Duff
2010-11-06  0:44                                   ` Jeffrey Carter
2010-11-06 21:10                                     ` Robert A Duff
2010-11-07  0:01                                       ` Brian Drummond
2010-11-07 20:41                                       ` Jeffrey Carter
2010-11-07 21:03                                         ` Yannick Duchêne (Hibou57)
2010-11-05  6:49                           ` J-P. Rosen
2010-11-05  7:05                           ` Florian Weimer
2010-11-05  7:20                             ` J-P. Rosen
2010-11-05 17:39                               ` Florian Weimer
2010-11-05 18:08                                 ` Georg Bauhaus
2010-11-05 23:36                                 ` J-P. Rosen
2010-11-06  1:05                                 ` Yannick Duchêne (Hibou57)
2010-11-05 10:58                             ` Georg Bauhaus
2010-11-05 16:31                               ` Dmitry A. Kazakov
2010-11-05 17:38                                 ` Georg Bauhaus
2010-11-05 17:31                               ` Florian Weimer
2010-11-05 18:02                                 ` Georg Bauhaus
2010-11-05 23:29                               ` J-P. Rosen
2010-11-06  0:00                                 ` Robert A Duff
2010-11-06  0:12                                   ` Simon Wright
2010-11-06 11:34                                   ` J-P. Rosen
2010-11-06  0:01                                 ` Georg Bauhaus
2010-11-09 20:43                             ` Warren
2010-11-05 17:24                         ` Robert A Duff
2010-11-05 20:05                           ` Vinzent Hoefler
2010-11-05 22:28                             ` Robert A Duff
2010-11-04 17:40                     ` Jeffrey Carter
2010-11-05 17:15                       ` Robert A Duff
2010-11-05 19:24                         ` Jeffrey Carter
2010-11-05 22:52                           ` Robert A Duff
2010-11-06  0:40                             ` Jeffrey Carter
2010-11-06  7:12                               ` Dmitry A. Kazakov
2010-11-06 10:13                                 ` Yannick Duchêne (Hibou57)
2010-11-06 11:00                                 ` Georg Bauhaus
2010-11-06 11:35                                   ` Dmitry A. Kazakov
2010-11-06 13:34                                     ` Simon Wright
2010-11-06 14:53                                       ` Dmitry A. Kazakov
2010-11-06 20:52                                   ` Shark8
2010-11-06 21:58                                     ` Yannick Duchêne (Hibou57)
2010-11-07  2:57                                       ` Shark8
2010-11-07  3:12                                         ` Yannick Duchêne (Hibou57)
2010-11-07  6:37                                         ` J-P. Rosen
2010-11-06 17:10                                 ` (see below)
2010-11-06 22:08                                   ` Niklas Holsti
2010-11-06 22:24                                     ` Yannick Duchêne (Hibou57)
2010-11-06  0:42                             ` Shark8
2010-11-06 13:24                               ` Robert A Duff
2010-11-06 21:20                                 ` Shark8
2010-11-06 22:12                                   ` Yannick Duchêne (Hibou57)
2010-11-16 20:33                                     ` Randy Brukardt
2010-11-06  1:33                             ` Yannick Duchêne (Hibou57)
2010-11-04 17:49                     ` Jeffrey Carter
2010-11-02 20:38                 ` Beginners question: Compound types, how-to? Jeffrey Carter
2010-11-02 20:59               ` Britt Snodgrass
2010-11-03  0:46                 ` Georg Bauhaus
2010-11-03  1:59                   ` Yannick Duchêne (Hibou57)
2010-11-03 12:59                     ` Georg Bauhaus
2010-11-03 15:28                       ` Georg Bauhaus
2010-11-03  8:58                   ` Dmitry A. Kazakov
2010-11-03 12:31                     ` Georg Bauhaus
2010-11-03 12:18                   ` Stephen Leake
2010-11-03 13:12                     ` Georg Bauhaus
2010-11-04  0:55                     ` Yannick Duchêne (Hibou57)
2010-11-03 17:35                   ` Vinzent Hoefler
2010-11-03 21:19                     ` Simon Wright
2010-11-03 21:31                       ` Vinzent Hoefler
2010-11-04  5:25                         ` Stephen Leake
2010-11-04 17:47                           ` Jeffrey Carter
2010-11-04  6:11                         ` Yannick Duchêne (Hibou57)
2010-11-04 19:30                           ` Vinzent Hoefler
2010-11-04 17:42                         ` Jeffrey Carter
2010-11-03 12:06               ` Stephen Leake
2010-11-04  1:04                 ` Yannick Duchêne (Hibou57)
2010-11-04 17:11                 ` Jeffrey Carter
2010-11-04 13:47               ` Peter C. Chapin
2010-11-04 14:30                 ` Warren
2010-11-01 17:24     ` Yannick Duchêne (Hibou57)
2010-11-01 21:31       ` Simon Wright
2010-11-01 19:05     ` Jeffrey Carter
2010-11-01 11:50   ` (see below)
2010-11-01 17:16     ` Yannick Duchêne (Hibou57)
2010-11-01 17:27       ` Georg Bauhaus
2010-11-01 17:41         ` Yannick Duchêne (Hibou57)
2010-11-01 17:55           ` Yannick Duchêne (Hibou57)
2010-11-01 18:12       ` Adam Beneschan
2010-11-01 19:25     ` Jeffrey Carter
2010-11-01 12:03 ` Brian Drummond
2010-11-01 12:17   ` Florian Weimer
2010-11-01 13:05   ` Mart van de Wege
2010-11-01 22:45     ` Brian Drummond
2010-11-01 23:17       ` Yannick Duchêne (Hibou57)
2010-11-02  8:32         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox