1 registered members (Ayumi),
900
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: temp var?
[Re: Frederick_Lim]
#145187
08/02/07 06:19
08/02/07 06:19
|
Joined: Aug 2005
Posts: 390 Florida
oldschoolj
Senior Member
|
Senior Member
Joined: Aug 2005
Posts: 390
Florida
|
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...
you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe.
__________________________________
yours truly
|
|
|
Re: temp var?
[Re: Frederick_Lim]
#145189
08/02/07 07:26
08/02/07 07:26
|
Joined: Oct 2003
Posts: 312 Lüneburg, Germany
Gnometech
Senior Member
|
Senior Member
Joined: Oct 2003
Posts: 312
Lüneburg, Germany
|
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
|
|
|
Re: temp var?
[Re: Frederick_Lim]
#145190
08/02/07 08:51
08/02/07 08:51
|
Joined: Aug 2005
Posts: 390 Florida
oldschoolj
Senior Member
|
Senior Member
Joined: Aug 2005
Posts: 390
Florida
|
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"..
Last edited by oldschoolj; 08/02/07 08:54.
you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe.
__________________________________
yours truly
|
|
|
Re: temp var?
[Re: Frederick_Lim]
#145192
08/02/07 09:00
08/02/07 09:00
|
Joined: Aug 2005
Posts: 390 Florida
oldschoolj
Senior Member
|
Senior Member
Joined: Aug 2005
Posts: 390
Florida
|
post the function that called the error
you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe.
__________________________________
yours truly
|
|
|
Re: temp var?
[Re: oldschoolj]
#145193
08/02/07 09:13
08/02/07 09:13
|
Joined: Oct 2003
Posts: 827 22�21'24"N 114�07'30"E
Frederick_Lim
OP
User
|
OP
User
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
|
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); }
|
|
|
|