Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Appending to arrays, printf() problem. #258112
03/27/09 19:19
03/27/09 19:19
Joined: Mar 2009
Posts: 4
I
IwanBronkowitsch Offline OP
Guest
IwanBronkowitsch  Offline OP
Guest
I

Joined: Mar 2009
Posts: 4
Hi,

I got two problems. First is: I have an array with data of my own class.

Code:
typedef struct { 
	int angX; 
[..more ints..]
	ENTITY* doorE;
} DOOR;
DOOR eDoors[0];

Later on I want to enlarge this array by pushing new DOORs to the end of the array stack. VB uses "redim preserve array()", java and actionscript use .push() and .pop() ..just those [not printable] c-derivatives make a great problem out of this - any fast, not complicated, human way to solve this problem?

Second is: How to printf() an integer?
Code:
int a;
a = 10;
a += ...
printf(a);


Sorry, I don't have the time to learn C and all those strange differences to other languages as this is not the only one project that I have.
Click to reveal..
1000 bucks for a buggy development environment, that puts spokes like this scripting language into my wheel (not mentioning this unhandy .map Editor (better use GTK Radiant), not mentioning the thin documentation, and last but not least: The great MED). Well done, Conitec. Jesus, it can't be so hard to make a rip off of some ideas from other software.


Thanks in advance,
IwanBronkowitsch

Re: Appending to arrays, printf() problem. [Re: IwanBronkowitsch] #258172
03/28/09 07:38
03/28/09 07:38
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
For changing array size in C/C++, use malloc and realloc

DOOR* eDoors;


...
eDoors = (DOOR*)malloc(100*sizeof(DOOR));
...
eDoors = (DOOR*)realloc(eDoors,200*sizeof(DOOR));

You need lite-C 1.7 because earlier versions dont support sizeof.

printf("a = %d",a); prints an integer.


Re: Appending to arrays, printf() problem. [Re: Tobias] #258173
03/28/09 07:46
03/28/09 07:46
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
Another, nice possibility would be to use the GSVector plugin made by pegamode.
It provides acces to the C++ std::vector class which is used for dynamically resizing arrays and such.

GSVector thread

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: Appending to arrays, printf() problem. [Re: KDuke] #258191
03/28/09 13:38
03/28/09 13:38
Joined: Mar 2009
Posts: 4
I
IwanBronkowitsch Offline OP
Guest
IwanBronkowitsch  Offline OP
Guest
I

Joined: Mar 2009
Posts: 4
Thank you smile

Another problem:

Code:
[...]
int animStat;
[...]
eDoors[i].animStat = integer(eDoors[i].rotRad / eDoors[i].maxRot * 100);

maxRot is 90, rotRad is growing from zero to 90. Why won't animStat become 100 and stays zero?

This is the full classdefinition of my door. If I use the muffin or malloc solution or whatever its called posted above, the "script" runs and the door does many things, but not the things I want it to do frown
Code:
var doorNum = 0;
	typedef struct { 
		int angX; 
		int angY; 
		int r;
		int rad;
		int rotrad;
		int stat; 
		int angl;
		int doorspeed;
		int maxRot;
		int dir;
		int rotTickles;
		int animStat;
		STRING* modellFile;
		var targetid;
		ENTITY* doorE;
	} DOOR;
DOOR* eDoors;
eDoors = (DOOR*)malloc(100*sizeof(DOOR));
addDoor(100,100,-320,0, "door.mdl",101,10,20,90,1);

function addDoor(dX,dY,dZ,dR,STRING* dModell,tid,dspd,radius,maxR,direction) {
		eDoors = (DOOR*)realloc(eDoors,100 + doorNum* 100*sizeof(DOOR));
}


Last edited by IwanBronkowitsch; 03/28/09 14:02.
Re: Appending to arrays, printf() problem. [Re: IwanBronkowitsch] #258195
03/28/09 15:04
03/28/09 15:04
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
because rotrad/maxrad can be 90/90 at max. which equals to 1.

it stays 0 beacuse it'is an integer, if you divide 2 integers result will be integer. 0-89/90 is aways 0.xxx, and it's int par is 0.

and you dont need to store ang_x and ang_y entity alreay has pan,tilt,roll angles.


3333333333
Re: Appending to arrays, printf() problem. [Re: Quad] #258431
03/30/09 15:47
03/30/09 15:47
Joined: Mar 2009
Posts: 4
I
IwanBronkowitsch Offline OP
Guest
IwanBronkowitsch  Offline OP
Guest
I

Joined: Mar 2009
Posts: 4
And yet another problem:

Code:
typedef struct { 
		  VECTOR* pos; 
		  VECTOR* dim;
		  int trType;
		  int trID;
		  var trActions[100];
		  var trActionTargets[100];
		  int tAN;
		  int tActive;
		  int usesDir;
		  int approxDir;
		  ENTITY* Et1;
} TRIGGER;
TRIGGER eTriggers[10];

If I call this function:

Code:
function playerwalk() { 

      var dist_down; 
      if (c_trace(wplayer.x,vector(wplayer.x,wplayer.y,wplayer.z-5000),USE_BOX) > 0) {
      	dist_down = wplayer.z + vFeet.z - target.z;
		} else {
			dist_down = 0;
		}   
      if (dist_down > 0) {
         dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
      } else {
         speed_down = 0;
      }
 
      var dist_ahead = 5*(key_w-key_s)*time_step;
      var dist_side = 5*(key_a-key_d)*time_step;
      dist_ahead = sign(dist_ahead)*(abs(dist_ahead) + 0.5*dist_down);
      dist_side = sign(dist_side)*(abs(dist_side) + 0.5*dist_down);
      c_move(wplayer,vector(dist_ahead,dist_side,0),vector(0,0,-dist_down), GLIDE);
}


the data in (for example)

Code:
eTrigger[1].pos.x = 50;
eTrigger[1].pos.y = 50;
eTrigger[1].pos.z = 50;
//and
eTrigger[1].dim.x = 50;
eTrigger[1].dim.y = 50;
eTrigger[1].dim.z = 50;

get lost. Sometimes - when I called the function above - the data in pos.x, pos.y is not 50 (or the desired value) anymore, it becomes -3800, or 0 etc..


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