|
|
Appending to arrays, printf() problem.
#258112
03/27/09 19:19
03/27/09 19:19
|
Joined: Mar 2009
Posts: 4
IwanBronkowitsch
OP
Guest
|
OP
Guest
Joined: Mar 2009
Posts: 4
|
Hi, I got two problems. First is: I have an array with data of my own class.
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?
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. 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: Tobias]
#258173
03/28/09 07:46
03/28/09 07:46
|
Joined: Mar 2009
Posts: 112 Germany
KDuke
Member
|
Member
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
IwanBronkowitsch
OP
Guest
|
OP
Guest
Joined: Mar 2009
Posts: 4
|
Thank you  Another problem:
[...]
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 
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
Senior Expert
|
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
IwanBronkowitsch
OP
Guest
|
OP
Guest
Joined: Mar 2009
Posts: 4
|
And yet another problem:
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: 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)
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..
|
|
|
|