2 registered members (vicknick, AndrewAMD),
1,292
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
pointer problems.
#408703
10/05/12 21:28
10/05/12 21:28
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
I have created a dashboard which can display the same type of information about different objects when they are selected. Imagine a board that show the 0-60 and top speed of cars, and when you selected that car it would pop up on that board. I do this by when you push a button it calls a function with calls another function which puts the proper vars to be displayed and those are ran through pointers of the function. Ex void create_information_display_fastcars(var* 060speed, var* topspeed, var* value) Now the function works just fine and the information displays shows the correct information. Now I want to mod that information. I create a few vars pointers that I want to mod in another function when i push the up and down arrows. However this is where my function starts working. I took a look at and went along the same lines as this http://rapidpurple.com/blog/tutorials/c-...-of-a-variable/but I can not get it to work. I thought it might be the digits that displays the number so i put up another to show the actual value of that number without any pointer action but nothing seems to change. Anyone have any idea?
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: pointer problems.
[Re: Superku]
#408717
10/05/12 22:53
10/05/12 22:53
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
Here is the main function that does most of the work
void create_information_display_seller(var* speed_v, var* health_v, var* damage_v, var* money_v, BMAP* bmap_b)
{
if(information_display_seller)pan_remove(information_display_seller);
//////////////////////////////
// now we use the pointers to use the buttons on
//////////////////////////////
seller_health = *health_v;
seller_damage = *damage_v;
seller_money = *money_v;
seller_speed = *speed_v;
//in another function seller_health, damge,money and
//speed will be altered and should affects the totals of the
//original vars that were passed into this function
information_display_seller = pan_create("",5);
information_display_seller.pos_x = 672;
information_display_seller.pos_y = 5;
//displays the image of the item selected
pan_setbutton(information_display_seller,0,1,
0,
0,
bmap_b,
bmap_b,
bmap_b,
NULL,
NULL,//function goes here
NULL,
NULL);
pan_setdigits(information_display_seller,0,150,115,"%2.f",font_create("Arial#25"),1,seller_speed);
pan_setbutton(information_display_seller,0,1,
235,
115,
UPARROW,UPARROW,UPARROW,
NULL,
alter_seller_speed_up,//function goes here
NULL,
NULL);
pan_setbutton(information_display_seller,0,1,
270,
115,
DOWNARROW,DOWNARROW,DOWNARROW,
NULL,
alter_seller_speed_down,//function goes here
NULL,
NULL);
set(information_display_seller,SHOW);
}
What I want to do is pass a variable into this function and assign that variable to a pointer so that variable can be manipulated later on.
Last edited by FoxHound; 10/05/12 22:59.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: pointer problems.
[Re: Superku]
#408720
10/05/12 23:08
10/05/12 23:08
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
problem solved.
seller_health = health_v; seller_damage = damage_v; seller_money = money_v; seller_speed = speed_v;
fixed my problem. So there did not need to be a * in front of health_v and the others.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: pointer problems.
[Re: Superku]
#408722
10/05/12 23:15
10/05/12 23:15
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
I'd say you scrap this approach and define a struct for your purpose that holds all the necessary information. Then use a linked list or an array of your struct instances and draw the information dynamically without panels using draw_text or draw_obj + text object. Every last bit of that will take a lot more resources (during game play) and coding then my method. I knew it was a simple error on my part somewhere in my code as altering a number through a pointer is on almost every "how to learn c" site out there, my only thing is I wanted to put a middle man in there and messed up something simple, which was trying to move pointer value instead of pointer address.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: pointer problems.
[Re: FoxHound]
#408724
10/05/12 23:20
10/05/12 23:20
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Every last bit of that will take a lot more resources (during game play) and coding then my method. It probably wouldn't, draw_quad is f.i. faster than using panels, but good that you've found the solution to your problem.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: pointer problems.
[Re: Superku]
#408725
10/05/12 23:27
10/05/12 23:27
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
not draw_quad but
define a struct for your purpose that holds all the necessary information. Then use a linked list or an array of your struct instances
would vs using basic vars and some pointer fun. And yes the problem is solved. I put it together for everything and it works just fine. I'm using this for a tool to make my real game. Wow I never knew I would need to make so many tools.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: pointer problems.
[Re: FoxHound]
#408733
10/06/12 10:18
10/06/12 10:18
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
if you want to change a var in another function do it like this:
void set_a_to_b(var* a, var b)
{
a[0] = b;
}
You have to give an array index. (the var a which is passed to the function doesn't have to be an array!) I'm not sure why it works or either how I foud out how It works - but it does.
POTATO-MAN saves the day! - Random
|
|
|
|