Advertisement

Pascal pointers

Started by February 22, 2003 12:21 AM
1 comment, last by gryfang 21 years, 8 months ago
I am currently trying to make a text based adventure game and am using a 4 pointer node structure (the four pointers are north south east and west) I have four procedures for moving the pointer where the protananist is currently at called heropos and I''m having trouble changing the pointer to point to a different room and then move from that room (change the pointer once again). I''ve also tried other directions and the north pointer works time after time until another direction is taken, and anytime east south or west is taken, I am unable to change the pointer after that. I''ve included code of declarations and teo of the 4 procedures... I''d like to get over this problem with the pointers and continue thank you for listening. type roominfo = record name, description : string; end; destin = ^room; room = record value : roominfo; north, south, east, west : destin; end; var waiting, den, training, reading, journey : room; heropos : destin; ... procedure gonorth; begin if (heropos^.north <> nil) then begin heropos^ := heropos^.north^; writeln (heropos^.value.name); writeln (heropos^.value.description) end else begin writeln (''There is no exit that way.'') end; end; procedure gosouth; begin if (heropos^.south <> nil) then begin heropos^ := heropos^.south^; writeln (heropos^.value.name); writeln (heropos^.value.description) end else begin writeln (''There is no exit that way.'') end; end; ... God bless -Gryfang
God bless-Gryfang
(It is many years since I coded Pascal so forgive me if I rusty)

Too me this seems to be the culprit:

heropos^ := heropos^.north^;

(and likewise for the other directions)

What you do is that you change what heropos is pointing to, i.e. the actual room. This is no what you want. What you want is to change the pointer itself, like this:

heropos := horopos^.north;

I hope this helps.



Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Advertisement
Thanks ... but it didn''t seem to work, and the gonorth procedure seems to work fine until the other three are ran. (if I had 100 node I could transverse them all with north, but as soon as either east, south, or west it taken it does change the pointer, but then you cannot take another direction because it treats them all as nil values (it displays the ''There is no exit that way.'' in the else). I don''t know what would be causing that. If there is a better way than linked list to do what I want to I''m open to suggestions also, but I figured this would be the best. Thank you for listening.

God bless
-Gryfang
God bless-Gryfang

This topic is closed to new replies.

Advertisement