Enterable object movement
rogeriobiondi opened this issue · 4 comments
Hello,
Sorry if my question is too basic and not a bug. I'm a beginner, not used to DM4/Inform and trying to implement a car movement, following the DM4 Manual
https://www.inform-fiction.org/manual/html/s15.html
!% -~S
!% $OMIT_UNUSED_ROUTINES=1
!% $ZCODE_LESS_DICT_DATA=1
! The very first lines of the main source code file for a game can
! contain compiler options, like the lines above. -~S disables
! strict error checking. This is otherwise used in z5 and z8 games by
! default. While useful for debugging, it adds ~10 KB to the story file
! size and it makes the game slower.
! $OMIT_UNUSED_ROUTINES=1 makes the compiler remove all routines which
! aren't used. This can save some space.
! $ZCODE_LESS_DICT_DATA=1 removes an empty data byte for every dictionary word.
Constant Story "Minimal";
Constant Headline "^A sample game which uses PunyInform.^";
! Uncomment ONE of the two following lines, to show either time or score/turns
! Leaving both commented out makes the library bigger.
!Constant STATUSLINE_TIME; Statusline time;
Constant STATUSLINE_SCORE; Statusline score;
! Comment out to keep track of score
! The value is what will be shown as the score on statusline in z3
Constant NO_SCORE = 0;
! Customize the statusline in z5+ (will have no effect in z3)
!Constant OPTIONAL_SL_NO_SCORE;
!Constant OPTIONAL_SL_NO_MOVES;
! Uncomment to add optional features to PunyInform
!Constant DEBUG;
!Constant CUSTOM_ABBREVIATIONS;
!Constant CUSTOM_PLAYER_OBJECT = myPlayerObj;
!Constant OPTIONAL_NO_DARKNESS;
!Constant OPTIONAL_ALLOW_WRITTEN_NUMBERS;
!Constant OPTIONAL_EXTENDED_METAVERBS;
!Constant OPTIONAL_EXTENDED_VERBSET;
!Constant OPTIONAL_FLEXIBLE_INVENTORY;
Constant OPTIONAL_PRINT_SCENERY_CONTENTS;
!Constant OPTIONAL_SCORED;
!Constant OPTIONAL_FULL_SCORE; ! Comment out NO_SCORE when uncommenting this
!Constant OPTIONAL_FULL_DIRECTIONS;
!Constant OPTIONAL_SIMPLE_DOORS;
!Constant OPTIONAL_SHIP_DIRECTIONS;
!Constant OPTIONAL_GUESS_MISSING_NOUN;
!Constant OPTIONAL_MANUAL_SCOPE;
!Constant OPTIONAL_MANUAL_REACTIVE;
!Constant OPTIONAL_ORDERED_TIMERS;
!Constant OPTIONAL_PROVIDE_UNDO;
!Constant OPTIONAL_REACTIVE_PARSE_NAME;
!Constant RUNTIME_ERRORS = 0; ! 0, 1 or 2. 0 = smallest file, 2 = most info
! Define any library constants you need here, like MAX_SCORE, AMUSING_PROVIDED,
! MAX_CARRIED, SACK_OBJECT, etc.
Constant INITIAL_LOCATION_VALUE = start;
Include "globals.h";
! Define your attributes, common properties and global variables here, if any
! Define the entry point routines you need here, like Amusing, DarkToDark etc.
! Uncomment to add PunyLib extensions
!Include "ext_menu.h";
!Include "ext_flags.h";
!Include "ext_talk_menu.h"; ! Note: Also include ext_flags.h to allow use of flags
!Include "ext_quote_box.h";
!Include "ext_cheap_scenery.h";
Include "puny.h";
! Uncomment to add PunyLib extensions
!Include "ext_waittime.h";
Class Road has light;
Road start "start"
with
description "start",
n_to km1;
Road km1 "km1"
with
description "km1",
n_to km2;
Road km2 "km2"
with
description "km2",
n_to km3;
Road km3 "km3"
with
description "km3",
n_to "Deadline!";
Object car "car"
with
name 'car',
found_in start,
description "my car.",
before [ loc_n;
Go:
if (selected_direction == n_to) {
loc_n = parent(car).n_to;
move car to loc_n;
<<Look>>;
}
],
has enterable static container open light;
[Initialise;
print "^^The road is dangerous. And so the story begins...^^";
];
In this example the car just runs forward (north).
When running this example the object car cannot be moved correctly:
The road is dangerous. And so the story begins...
Minimal
A sample game which uses PunyInform.
Release 1 / Serial number 220802 / Inform v6.36 PunyInform v4.0 D
start
start
You can see a car (providing light) (which is empty) here.
> tree
start
car
yourself
> enter the car
You enter the car.
> tree
start
car
yourself
> n
First, you'd have to leave the car.
> tree
start
It seems that if I move the car with the player inside, the object tree breaks.
I read that PunyInform implements the compass differently from DM4. How should the movement be handled?
Thank you very much.
Kindly regards,
Rogerio
Just after the table of return values in the example in DM4, there is this sentence: "If you want to move the vehicle in your own code, return 3, not 2: otherwise the old location may be restored by subsequent workings." You haven't done this, and that's why you get into trouble.
Anyway, it looks like you can get the effect you want without moving the car yourself. Just return 1 ( = true) when you want to allow the movement, and the library will move both the car and the player.
As for how to find the correct direction property, you would do something like this:
before [ loc_n prop;
Go:
prop = direction_properties_array->selected_direction_index;
loc_n = parent(car).prop;
move car to loc_n;
<Look>;
return 3;
],
As you noted, this isn't really the best support channel. I recommend you join our Discord server at https://discord.com/invite/y9anzKJTBa or post questions at https://intfiction.org/ (Use the Inform category, and tag the post PunyInform).
EDIT: I fixed a typo in the code in my reply.
Thank you very much for you help, Fredrikr. I'll join the Discord server and the intfiction.org forum.
Kind regards,
Rogerio
You're welcome, and see you on Discord and the forum!
BTW, you can read up on how directions are handled in the manual: https://github.com/johanberntsson/PunyInform/wiki/Manual#direction-handling