Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 16,232 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Structs and Strings #327055
06/04/10 12:12
06/04/10 12:12
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
I'm having some trouble using structs, specifically structs containing STRING*s

It seems that when I copy a string into the member of my struct only the first character is stored. Is there something people usually get wrong with working with structs that results in this?

Re: Structs and Strings [Re: The_Clyde] #327057
06/04/10 12:21
06/04/10 12:21
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
make sure to do a str_create(""); first, and then str_cpy whatever content you want in the string.
I've done it before, and works perfectly fine.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Structs and Strings [Re: Helghast] #327060
06/04/10 12:26
06/04/10 12:26
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
Ahh okay- I guess thats *not* a time to malloc then...

Re: Structs and Strings [Re: The_Clyde] #327062
06/04/10 12:32
06/04/10 12:32
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
could you show the code for initialising the struct and the piece where you copy the string?
that will make it easier for us laugh

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Structs and Strings [Re: Helghast] #327067
06/04/10 12:46
06/04/10 12:46
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
Well, that specific problem is solved but I'll post some code anyway, since I am having some other weird problems like members of structs not initializing correctly.
Code:
typedef struct Cue {
	STRING* entname;
	VECTOR* startpos;
	VECTOR* endpos;
	ANGLE* startang;
	ANGLE* endang;
	VECTOR* startscale;
	VECTOR* endscale;
	STRING* anim; //animation name- or NULL
	var animloops;
	var starttime;
	var duration;
	struct Cue* next; //used when the cue is in the linked list of active cues
	struct Cue* prev;
} Cue;

typedef struct Keyframe {
	var cuetime;
	var actions_count;
	Cue* actions[64];
} Keyframe;



Keyframe* scene;
Cue* active_cues[300];
var keyframe_count;
Cue* active_cues_head = NULL;

function newCue()
{
	Cue* newcue = malloc(sizeof(Cue));
	memset(newcue,0,sizeof(Cue));
	return newcue;
}

function newKeyframe()
{
	Keyframe* newkeyframe = malloc(sizeof(Keyframe));
	memset(newkeyframe,0,sizeof(Keyframe));
	return newkeyframe;
}

function loadScene(STRING* filename)
{
	str_cpy(delimit_str," ");
	var filehandle = file_open_read(filename);
	
	var length = file_var_read(filehandle); //first number is number of keyframes to malloc
	scene = malloc(length * sizeof(Keyframe));
	var i;
	for(i = 0; i < length; i++)
	{
		
		memcpy(scene[i],newKeyframe(),sizeof(Keyframe));
		scene[i].cuetime = file_var_read(filehandle);
		scene[i].actions_count = file_var_read(filehandle);
		
		
		if(scene[i].actions_count > 0)
		{
			
			scene[i].actions = malloc(scene[i].actions_count * sizeof(Cue));
			var k;
			for(k = 0; i < scene[i].actions_count; i++)
			{
				scene[i].actions[k] = newCue();
				scene[i].actions[k].entname = str_create("#20");
				file_str_read(filehandle,scene[i].actions[k].entname);
				
				scene[i].actions[k].startpos = vector(0,0,0);
				scene[i].actions[k].endpos = vector(0,0,0);
				scene[i].actions[k].startang = vector(0,0,0);
				scene[i].actions[k].endang = vector(0,0,0);
				scene[i].actions[k].startscale = vector(0,0,0);
				scene[i].actions[k].endscale = vector(0,0,0);
				
				scene[i].actions[k].startpos.x = file_var_read(filehandle);
				scene[i].actions[k].startpos.y = file_var_read(filehandle);
				scene[i].actions[k].startpos.z = file_var_read(filehandle);
				scene[i].actions[k].endpos.x = file_var_read(filehandle);
				scene[i].actions[k].endpos.y = file_var_read(filehandle);
				scene[i].actions[k].endpos.z = file_var_read(filehandle);
				scene[i].actions[k].startang.pan = file_var_read(filehandle);
				scene[i].actions[k].startang.tilt = file_var_read(filehandle);
				scene[i].actions[k].startang.roll = file_var_read(filehandle);
				scene[i].actions[k].endang.pan = file_var_read(filehandle);
				scene[i].actions[k].endang.tilt = file_var_read(filehandle);
				scene[i].actions[k].endang.roll = file_var_read(filehandle);
				scene[i].actions[k].startscale.x  = file_var_read(filehandle);
				scene[i].actions[k].startscale.y = file_var_read(filehandle);
				scene[i].actions[k].startscale.z = file_var_read(filehandle);
				scene[i].actions[k].endscale.x = file_var_read(filehandle);
				scene[i].actions[k].endscale.y = file_var_read(filehandle);
				scene[i].actions[k].endscale.z = file_var_read(filehandle);
				file_str_read(filehandle,scene[i].actions[k].anim);
				scene[i].actions[k].animloops = file_var_read(filehandle);
				scene[i].actions[k].starttime = scene[i].cuetime;
				scene[i].actions[k].duration = file_var_read(filehandle);
				
				
				scene[i].actions[k].next = NULL;
				scene[i].actions[k].prev = NULL;
				
			}
		}
		
	}
	file_close(filehandle);
}



This is actually for the AUM tools contest- I'm working on what I hope will be a nice treat for all GS users grin

Re: Structs and Strings [Re: The_Clyde] #327079
06/04/10 14:10
06/04/10 14:10
Joined: Jul 2008
Posts: 223
Pittsburgh
The_Clyde Offline OP
Member
The_Clyde  Offline OP
Member

Joined: Jul 2008
Posts: 223
Pittsburgh
Ahh yes! I got it working finally grin

It turned out I was trying to manipulate a static entity. tongue


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

Gamestudio download | 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