Text-based game - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Text-based game

Hey, I'm trying to learn BASIC by writing a text-based game. Where I'm at now is trying to figure out how to do the inventory. Now, I was thinking that, whenever someone picks up, say, a gun, then it writes that to a file. How do I do that, though? I tried using the "open...append" and then "Write" commands to write to the file whenever someone picked it up, but then how do I get the program to go back and check that? I also tried to use the "open...binary" command to write to the file in binary, but that didn't work out well. Any ideas? Can I do an inventory without opening another file?


  • Try this:

    If the player has picked up the gun, the variable gun should be filled with 1.

    gun = 1

    Now you can check the inventory very easy:

    if gun = 0 ( NO GUN )

    if gun = 1 ( ALREADY PICKED UP GUN )

    For save-games you can save the inventory like this:

    if gun = 1 then
    open "savegame.001" for output as #1
    print #1,"gun1"
    open "savegame.001" for output as #1
    print #1,"gun0"
    end if

    open "savegame.001" for imput as #1
    input #1,inventory$

    if inventory$ = "gun1" then gun = 1
    gun = 0
    end if

  • It's always the easiest way! Here I was screwing around with all these complicated commands and all I had to do was...uck, never mind. My head hurts. *L* Thanks a lot for your help. Very much appreciated, man.

Sign In or Register to comment.