Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, AndrewAMD), 1,292 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
pointer problems. #408703
10/05/12 21:28
10/05/12 21:28
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline 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: FoxHound] #408711
10/05/12 22:03
10/05/12 22:03
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
It's obviously difficult to guess your problem without having seen any code, but the following example works fine (I assume it's something you are aiming for):

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

var speed = 50;

void change_speed(var* spd, var value)
{
	*spd = value;
}

void main()
{
	fps_max = 60;
	while(1)
	{
		if(key_space) change_speed(&speed, total_ticks);
		DEBUG_VAR(speed,20);
		wait(1);
	}
}



"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] #408717
10/05/12 22:53
10/05/12 22:53
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Here is the main function that does most of the work
Code:
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: FoxHound] #408719
10/05/12 23:04
10/05/12 23:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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.


"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] #408720
10/05/12 23:08
10/05/12 23:08
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline 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 Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Originally Posted By: Superku
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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Quote:
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 Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
not draw_quad but

Code:
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
if you want to change a var in another function do it like this:

Code:
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. grin


POTATO-MAN saves the day! - Random
Re: pointer problems. [Re: Kartoffel] #408734
10/06/12 10:56
10/06/12 10:56
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
crazy
[offtopic]
it would be better treating the pointer as a pointer

Code:
*a = b;


[/offtopic]

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1