temp var?

Posted By: Frederick_Lim

temp var? - 08/02/07 05:38

Is the temp variable removed in lite-c?
Posted By: oldschoolj

Re: temp var? - 08/02/07 06:19

I'm definately not a coder, but this DOES work, from my experience.
Usually all you have to do is put something like this at the beginning of your script (if it's a vector your talking about):

Vector temp; // you must define vectors in Lite-C
vec_zero (temp); // and then zero it out before use

Now you can use it in the function, or action your needing it for. just remember though, if it's a different "temp" then create a new vector for each one:

Vector temp1;
vec_zero (temp1);

etc...
Posted By: Frederick_Lim

Re: temp var? - 08/02/07 06:37

I see, because C-script has temp build-in.

So is there any different for the following? In c-script I just use temp for both.

VECTOR temp;
ANGLE temp;
Posted By: Gnometech

Re: temp var? - 08/02/07 07:26

In fact there is.

When I used the vec_rotate command it sometimes led to weird results when the second argument was a VECTOR and not an ANGLE.

Example:

The code

Code:

...
vec_rotate(temp, vector(angle, 0, 0));
...



did not work properly all the time (here "angle" is just a var), but the code:

Code:

ANGLE temp_ang;

...
temp_ang.pan = angle;
temp_ang.tilt = 0;
temp_ang.roll = 0;
vec_rotate(temp, temp_ang);
...



works. It was a little confusing at first, but it seems that the casting from VECTOR to ANGLE and back, easy as it might seem, causes internal problems.

Regards,
Gnometech

P.S.: BTW the "temp" I used above is a VECTOR variable I had to defined, it is not predefined anymore. Maybe it would be worth a suggestion to move such C-Script pre-defined things (like ENTITY* player;) into default.c
Posted By: oldschoolj

Re: temp var? - 08/02/07 08:51

You must define Vectors for each operation that you want to do, just define them at the beginning of your code, it's worked for me thus far. You don't however have to define them for predefined entities (my, you, etc)
I believe the exact words from the manual are "always initialize variables"..
Posted By: Frederick_Lim

Re: temp var? - 08/02/07 08:56

I convert my c-script to lite-c, and compile successfully.

But I got lot of E1513 crash when I run the program.

I use ent_create a lot, what is the trick to avoid crash?
Posted By: oldschoolj

Re: temp var? - 08/02/07 09:00

post the function that called the error
Posted By: Frederick_Lim

Re: temp var? - 08/02/07 09:13

This will crash the main()
Code:
#include <default.c>

STRING* testLevel = "level0.wmb";
BMAP* crosshair = "crosshairsmall.pcx";
VECTOR* mouse_target; // mouse target position in 3D world

// Get the target vector

function get_target()
{
my.push = 2;
set(me,INVISIBLE);
VECTOR* vecFrom;
VECTOR* vecTo;
vec_zero(vecFrom);
vec_zero(vecTo);

while(1)
{
//store the mouse position to vecFrom
vecFrom.x = mouse_pos.x + mouse_spot.x;
vecFrom.y = mouse_pos.y + mouse_spot.y;
vecFrom.z = 1;//close point
vec_set(vecTo,vecFrom); //set the vecTo same as vecFrom
vec_for_screen(vecFrom,camera); //world position of mouse position
vecTo.z = 5000;//vecTo 10000 away from camera
vec_for_screen(vecTo,camera);//far point
c_trace(vecFrom, vecTo, IGNORE_PASSABLE|IGNORE_PUSH);//trace a line between the two points
vec_set(mouse_target,target); //put the c_trace target vector to mouse_target
wait(1);
}
}


function main()
{
level_load(testLevel);
wait(2); // wait until the level is loaded

vec_zero(mouse_target);
mouse_range = 3000; //mouse range from camera
mouse_mode = 1; //make cursor visible and moving
mouse_pointer = 0;
mouse_map = crosshair; //mouse bmap
mouse_spot.x = bmap_width(crosshair)/2; // hot spot in the bmap center
mouse_spot.y = bmap_height(crosshair)/2;
wait(1);
video_switch(6,0,2);

ent_create("crosshairsmall.pcx", nullvector, get_target);
}


Posted By: Gnometech

Re: temp var? - 08/02/07 09:24

Do not use vec_zero to intiialize a pointer. Use it to initialize a "pointee".

In other words: vec_to and vec_from should be of type VECTOR and not VECTOR*.
------------------------------------------------------------------
Alternatively you could initialize the pointers by writing:

vec_to = vector(0,0,0);

The "vector" instruction will return a pointer, just what we need here. So, in this case, you could continue writing VECTOR*. One of the two approaches should work, the second one does for me.

Gnometech
Posted By: Frederick_Lim

Re: temp var? - 08/02/07 09:37

I see. Thank you!
Posted By: Frederick_Lim

Re: temp var? - 08/02/07 13:54

I have another problem, FAT and NARROW seems no work for me, the entity always set to default hull. What's wrong with my code?

Code:
	set(me, NARROW);
set(me, FAT);
wait(1);
vec_set(my.max_x,vector(32,32,37));
vec_set(my.min_x,vector(-32,-32,-27));


Posted By: Ottawa

Re: temp var? - 08/02/07 15:17

try my.efalgs |= NARROW;

or

c_setminmax (ENTITY* ent)

Hope this helps!
© 2024 lite-C Forums