Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:06:19+00:00 2026-05-31T09:06:19+00:00

I am currently working on a text based game in C and I’m having

  • 0

I am currently working on a text based game in C and I’m having a problem altering values when certain events happen. Here is some of my data structure code:

typedef struct player { 
        int maxhealth;
        int curhealth;
        int in_combat;
        monster c_enemy;
        char *class;
        char *condition;
        rooms c_room;
        inventory i;
        stats stats;
    } player;

Now, I think my problem is that I currently have c_room (Current Room) as a rooms, instead of a pointer to a rooms. This affects me later because I need to alter things like n_monsters within the struct rooms for the current room. However, when I modify it by doing p.c_rooms.n_monsters -= 1; I’m not sure it alters the actual value of n_monsters for the room that I should be referring to. I’ve tested this by leaving a room when n_monsters is 0, and then coming back to see that it’s back at 1, the default value.

So yea, how would I point to right room?
Just:

typedef struct player {         
        int maxhealth;
        int curhealth;
        int in_combat;
        monster c_enemy;
        char *class;
        char *condition;
        rooms *c_room; // Like this?
        inventory i;
        stats stats;
    } player;

// And then the assignment would look like:
c_room = *rooms[3]; <- an array of rooms for the dungeon in the game.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:06:20+00:00Added an answer on May 31, 2026 at 9:06 am

    Assuming that c_room is a plain struct and not a pointer then you are right.

    If you have

    struct A {
      int v;
    };
    
    struct B {
      struct A a;
    }
    
    A a;
    a.v = 3;
    
    B b;
    b.a = a;
    

    This will actually copy the content of a inside B.a since they are assigned by value. They will be two different A, any modification to one of them won’t be reflected on the other.

    In your situation I would do something like:

    struct Room {
      // whatever
    }
    
    struct Room rooms[MAX_ROOMS];
    
    struct Player {
      struct Room *room;
    }
    
    Player p;
    p.room = &rooms[index];
    

    Now you will be able to correctly reference to room by p->room, it will be just a pointer to the actual room.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working through some exercises in a c++ book, which uses text based
I am currently working on a text based web game, where in I simulate
I'm currently working on a little text-based game after watching the new Tron movie
I'm currently working on a programming assignment for school. It's a simple text-based RPG.
I'm currently working on a project where I hide/show some table rows based on
I'm working on a site http://www.infinite-possibility.com/ which is currently having a problem with any
I'm working on a text-based adventure game and I'm trying to externalise as much
I'm currently working on some code based on John Resig - Simple JavaScript Inheritance
I am working on a text-based game in Python 3.1 that would use timing
I am currently working on a project and my goal is to locate text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.