I've been studying Pascal at school and I'm trying to write a text based rpg, so lots of string and integer manipulation. I want to take values from a record I have defined and place them in some universal variables. The user inputs some text which is assigned to a variable. If that text value has already been defined as being a record, I want it to take a value from that record and do stuff to it, if it's not a record, I want it to say something like 'That's not a record'.
Here's a bit of code to show what I mean, instead of setting record data as variables, I'm siply trying to display them:
*First problem. The standard comparison operators only seem to work with actual values. Here I need to see if the variable is of the type monkey.
**Second problem. I gat 'Illegal Identifier' for the .name part, it probably doesn't like using a variable as the record name.
Any ideas? I've googled for ages and can't find anything, I'm stumped.
Here's a bit of code to show what I mean, instead of setting record data as variables, I'm siply trying to display them:
Code:
program monkeyrecords;
type monkey=record
name : string;
legs : integer;
end;
var
chosen:string;
monk1:monkey;
BEGIN
monk1.name := 'Mr. Monkey';
monk1.legs := 5;
writeln ('choose a monkey');
readln (chosen);
if (chosen)=monkey*
then begin
writeln ('Monkey is called');
writeln ((chosen).name);**
writeln ('He has');
writeln ((chosen).legs);**
writeln ('legs');
end
if (chosen)<>monkey*
begin
write (chosen);
writeln ('is not a monkey');
end;
readln;
END.
*First problem. The standard comparison operators only seem to work with actual values. Here I need to see if the variable is of the type monkey.
**Second problem. I gat 'Illegal Identifier' for the .name part, it probably doesn't like using a variable as the record name.
Any ideas? I've googled for ages and can't find anything, I'm stumped.