Thread: Help..having trouble passing parameters

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    17

    Question Help..having trouble passing parameters

    I am having problem with a small code segment,the segment is part of a large project, everything else workd properly and this problem appears to be issolated..i am trying to pass two integer values from one function to another..there appears to be nothing wrong with it, but when I debug, the values I am passing from one function are not what the other function are receiving...

    prototypes inside header file:
    bool draw_gemstones(struct PacmanBoard* pcmb_p);

    bool init_gemstones(struct Gemstone *gem_p,struct PacmanBoard* pcmb_p,double size,int x,int y);




    im calling init_gemstones() inside draw_gemstones()....

    "init_gemstones(gemstn_p[0],pcmb_p,0.5,1,0);.."

    i want int x=1 and inty=0, but when im debugging and i look inside init_gemstones() i get int x=11805864 and y=11805864

    it seems, like its something simple. I just cant see whats wrong..please help!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    The debugger output of x and y values look more like addresses. Sure you're passing their values and not their locations. Post more of the code so that someone may be able to pinpoint the mistake.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    17
    Ya thats what I thought at first, but I dont see how that can be when Im passing the actual numbers 0 and 1, and also the size (0.5) is being passed properly.. heres the entire code..

    Code:
    #include "gemstone.h"
    #include "board.h"
    
    bool draw_gemstones(struct PacmanBoard* pcmb_p){
    
    	int Number_of_Gems=40;
    
    	struct Gemstone *gemstn_p[40];
    
    	gemstn_p[0]=(struct Gemstone*)malloc(sizeof(struct Gemstone));
    
    	init_gemstones(gemstn_p[0],pcmb_p,0.5,1,0);
    
    	draw_Polygon(gemstn_p[0]->gemstone);
    
    	destruct_Polygon(gemstn_p[0]->gemstone);
    
    
    return true;
    }
    
    bool init_gemstones(struct Gemstone* gem_p,struct PacmanBoard* pcmb_p,double size,int x,int y){
    
    
    	construct_Polygon(&gem_p->gemstone);
    	gem_p->position=(struct Point*)malloc(sizeof(Point));
    
    
    	//get dimensions of individual cell
    	double cell_w = pcmb_p->width / (double)(pcmb_p->ncells_x);
    	double cell_h = pcmb_p->height / (double)(pcmb_p->ncells_y);
    
    	struct Point* points = (struct Point*)malloc(4*sizeof(Point));
    
    	//find center position of cell
    	gem_p->position->x=0;//1+(x*cell_w)+(cell_w/2);
    	gem_p->position->y=0;//1-(y*cell_h)+(cell_h/2);
    
    	points[0].x=gem_p->position->x-cell_w*(size/2);
    	points[0].y=gem_p->position->y;
    	
    	points[1].x=gem_p->position->x;
    	points[1].y=gem_p->position->y+cell_h*(size/2);
    
    	points[2].x=points[0].x+size*cell_w;
    	points[2].y=points[0].y;
    
    	points[3].x=points[1].x;
    	points[3].y=points[1].y-size*cell_h;
    
    	init_Polygon(gem_p->gemstone, gem_p->position, 4, points, 1.0, 1.0, 1.0);
    
    
    
    return true;
    }

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    17
    SORRY, I had to repost it because I changed part of the code for debugging perposes, heres the code in original form


    Code:
    #include "gemstone.h"
    #include "board.h"
    
    bool draw_gemstones(struct PacmanBoard* pcmb_p){
    
    	int Number_of_Gems=40;
    
    	struct Gemstone *gemstn_p[40];
    
    	gemstn_p[0]=(struct Gemstone*)malloc(sizeof(struct Gemstone));
    
    	init_gemstones(gemstn_p[0],pcmb_p,0.5,1,0);
    
    	draw_Polygon(gemstn_p[0]->gemstone);
    
    	destruct_Polygon(gemstn_p[0]->gemstone);
    
    
    return true;
    }
    
    bool init_gemstones(struct Gemstone* gem_p,struct PacmanBoard* pcmb_p,double size,int x,int y){
    
    
    	construct_Polygon(&gem_p->gemstone);
    	gem_p->position=(struct Point*)malloc(sizeof(Point));
    
    
    	//get dimensions of individual cell
    	double cell_w = pcmb_p->width / (double)(pcmb_p->ncells_x);
    	double cell_h = pcmb_p->height / (double)(pcmb_p->ncells_y);
    
    	struct Point* points = (struct Point*)malloc(4*sizeof(Point));
    
    	//find center position of cell
    	gem_p->position->x=1+(x*cell_w)+(cell_w/2);
    	gem_p->position->y=1-(y*cell_h)+(cell_h/2);
    
    	points[0].x=gem_p->position->x-cell_w*(size/2);
    	points[0].y=gem_p->position->y;
    	
    	points[1].x=gem_p->position->x;
    	points[1].y=gem_p->position->y+cell_h*(size/2);
    
    	points[2].x=points[0].x+size*cell_w;
    	points[2].y=points[0].y;
    
    	points[3].x=points[1].x;
    	points[3].y=points[1].y-size*cell_h;
    
    	init_Polygon(gem_p->gemstone, gem_p->position, 4, points, 1.0, 1.0, 1.0);
    
    
    
    return true;
    }

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Nothing jumps out - can you post the debugger output also.

  6. #6
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Are you useing gcc to compile? If so I would use the following options:

    -Wall -pedantic

    Just curios if you are getting any warning or so here. Also since you are basing your logic of your coords from this code:

    Code:
       gem_p->position->x=1+(x*cell_w)+(cell_w/2);
       gem_p->position->y=1-(y*cell_h)+(cell_h/2);

    Would be good to check what your x and y are for your gem_p members are at that point in your code.

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    17
    there is no output from the debugger, it runs the program as it supposed to..im trying to draw a picture of a gemstone on a background (for a classics pacman game)..im assuming it is still drawing the gemstone, because my x and y values are being changed, it is probably just drawing it out of the screen...im using Visual C++...ive just noticed that its always telling me that
    gem_p->position->x and gem_p->position->y are unknow

    the structures are as followed
    gem_p:
    Code:
    struct Gemstone {
    
    	struct Point *position;
    	struct Polygon *gemstone;
    	//with respect to the size of a cell
    	double size;
    	//score value
    	int value;
    
    
    };
    position:
    Code:
    struct Point{
       
    double x;
    double y;
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 01:08 PM
  2. Passing parameters between templated functions
    By SpaceCadet in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2006, 03:57 PM
  3. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  4. passing templates as parameters - something funky?
    By archetype in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2002, 08:38 PM
  5. Passing parameters to other programs...is it possible?
    By face_master in forum Windows Programming
    Replies: 3
    Last Post: 01-28-2002, 07:48 AM