Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 877 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
temp var? #145186
08/02/07 05:38
08/02/07 05:38
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline OP
User
Frederick_Lim  Offline OP
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Is the temp variable removed in lite-c?

Re: temp var? [Re: Frederick_Lim] #145187
08/02/07 06:19
08/02/07 06:19
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

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: oldschoolj] #145188
08/02/07 06:37
08/02/07 06:37
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline OP
User
Frederick_Lim  Offline OP
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
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;

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 Offline
Senior Member
Gnometech  Offline
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


Download our playable Movement & Interaction Tutorial for 3DGS here:
http://www.puppenheim.org/MITutorial.zip
Re: temp var? [Re: Frederick_Lim] #145190
08/02/07 08:51
08/02/07 08:51
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

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: oldschoolj] #145191
08/02/07 08:56
08/02/07 08:56
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline OP
User
Frederick_Lim  Offline OP
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
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?

Re: temp var? [Re: Frederick_Lim] #145192
08/02/07 09:00
08/02/07 09:00
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

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 Offline OP
User
Frederick_Lim  Offline 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);
}



Re: temp var? [Re: Frederick_Lim] #145194
08/02/07 09:24
08/02/07 09:24
Joined: Oct 2003
Posts: 312
Lüneburg, Germany
Gnometech Offline
Senior Member
Gnometech  Offline
Senior Member

Joined: Oct 2003
Posts: 312
Lüneburg, Germany
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


Download our playable Movement & Interaction Tutorial for 3DGS here:
http://www.puppenheim.org/MITutorial.zip
Re: temp var? [Re: Gnometech] #145195
08/02/07 09:37
08/02/07 09:37
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline OP
User
Frederick_Lim  Offline OP
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
I see. Thank you!

Page 1 of 2 1 2

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