Thread: interactive book

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    21

    interactive book

    hello all, I'm working on an idea to make a text style game, but rather its more like a book. the setup is giving narratives, then 3-4 choices at the end. I want to make it very in depth, with multiple endings.. when i rough draft the idea in my head, I believe i could get away with doing this using only IF and ELSE IF statements, here's an example of what I'm thinking-


    scenery set up, setting description, character position,
    1.do this
    2.do that
    3.do this other thing

    1. would branch off too another paragraph, as would 2. and 3.
    and after each would be 3 more options.
    rinse and repeat. over and over again.

    so i would just like to know a few things from some more experienced programmers (I just started yesterday, but am a quick learner). I realize I shouldn't jump into too big of a project, but i feel like if i map out the story on paper it would just be a matter of writing and declaring options. do you think i could pull this off using only IF and ELSE IF statements, declaring char a=1, b=2, c=3? should i continue in the tutorial (from this website) to learn about Boolean operators? I have a rough draft coded-Untitled2.c
    (don't pay attention to the story, i'm still just testing the format)
    any advice or tips would be greatly appreciated!!
    cheers

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I'm imagining one of those "choose your own adventure" type books I used to read as a kid.

    I'd ordinarily advise against starting something like this on only your second day, but you seem to realize this, and I certainly don't want to discourage someone who is eager about learning and creating.

    I'm also sure that you're aware that, if you continue to learn, you'll be able to do a project like this much easier by mixing the various basics (writing functions, "switch" statements, loops, etc) instead of just if-else statements.

    However, it can be done with if-else statements - although it will be ugly and limited. Also, unless you're familiar with loops, you wouldn't be able to pick a piece of story that preceded a current one (which can easily happen in these types of stories).

    Definitely map it out on paper, as you mentioned. You might want to consider typing up each possible block of text and assign a number to it, as well as the associated choices and which numbers they would branch to. This way each one will have its own identification value, which can be assigned to the input variable when that choice is selected.

    Code:
    // pseudo code
    
    if(input is 1)
        (print first message)
        (does user want to do (2) something or (3) something else?)
    if(input is 2)
        (print something)
        (more choices)
    if(input is 3)
        (print something else)
        (more choices)
    // etc
    Also, you're assigning numbers to variables (a, b, c) that don't appear to change their value, and are just used for comparison. Why not just ditch those extra variables and compare the user input against number constants:

    Code:
    // what you have
    
    char a = 1;
    char b = 2;
    char c = 3;
    int answer;
    
    scanf("%d",&answer)
    if(answer == a)
        // do something
    if(answer == b)
        // do something else
    if(answer == c)
        // do something different
    Code:
    // what might be better
    
    int answer;
    
    scanf("%d",&answer)
    if(answer == 1)
        // do something
    if(answer == 2)
        // do something else
    if(answer == 3)
        // do something different

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Variables are just that, meant to vary. There's no sense in taking up extra space with constants that could be either directly compared against or #defined, especially when doing so makes the code more difficult to read.

    And FWIW, you should be posting code with code tags, instead of forcing us to download a file.

    Edit: I know it's probably too complicated for a beginner project, but this sounds like a good use for linked lists.

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    21
    thanks matticus, It does sound a better idea to learn everything first, which will allow for a faster, smoother coding later on. My head is filled with so many imaginative ideas and i just want them to manifest into a working program, but the world doesn't work that way, does it? assigning value to variables shows how much I'm getting ahead of myself (NOOB PROBLEMS), luckily there are greater programmers to set me in line.

    memcpy apologies for the attachment, i tried deleting/editing the thread to fix it, but i could not for the life of me find that option.. i realized right after doing so that people don't have time to just download my codes and review them, as if they get paid to do it! so next time... next time...

    thanks very much for taking the time to help, I'm gonna hit the books (online tutorials) and just try to learn as much as i can without a crazy big goal in mind.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interactive C Tutorial
    By Gigabitten in forum C Programming
    Replies: 4
    Last Post: 12-18-2011, 08:10 PM
  2. Interactive vs non-interactive terminal session question
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 06-18-2009, 07:30 PM
  3. Interactive Programs
    By creativeinspira in forum Linux Programming
    Replies: 0
    Last Post: 09-09-2007, 03:02 AM
  4. Interactive Telnet
    By PenguinFeva in forum C Programming
    Replies: 4
    Last Post: 05-27-2005, 09:28 PM
  5. Interactive C
    By Kaiya in forum C Programming
    Replies: 1
    Last Post: 09-30-2004, 08:20 PM