|
|
|
2 registered members (3run, AndrewAMD),
667
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: wdl -> lite-c conversion question
[Re: ello]
#143891
07/27/07 23:40
07/27/07 23:40
|
Joined: Aug 2006
Posts: 652 Netherlands
bstudio
User
|
User
Joined: Aug 2006
Posts: 652
Netherlands
|
Code:
function vec_randomize(var* vec, range) { vec[0] = random(1) - 0.5; vec[1] = random(1) - 0.5; vec[2] = random(1) - 0.5; vec_normalize(vec,random(range)); }
try this, the range might have to be indicated by an int but i don't know for sure
BASIC programmers never die, they GOSUB and don't RETURN.
|
|
|
Re: wdl -> lite-c conversion question
[Re: ello]
#143892
07/28/07 09:12
07/28/07 09:12
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Quote:
Code:
function vec_randomize (&vec, range) { vec[0] = random(1) - 0.5; vec[1] = random(1) - 0.5; vec[2] = random(1) - 0.5; vec_normalize(vec,random(range)); }
If you want to switch completely to Lite-C there are a few things you should consider (or be aware of). Lets take this piece of code for example:
- try to forget about "function" functions ^^ try to add return types. If you don't return anything, use void here.
- Always specify the parameter types. the "&" in CScript indicated a var array of 3 elements. So if you want to pass a Var[3] array, using var* as type is right: arrays are passed as pointers to the first element of the array. If you use then [ ], the size in bytes of the first item is multiplied with the number in the brackets to get the adress of the desired variable (this is also the reason why LiteC doesn't give an error if you exceed an array).
- be careful about VECTORs, ANGLEs and var [3] arrays. Although they have the same datastructure, you should take care of it when you pass e.g. a var[3] to an engine function which expects a VECOR* struct. Add a cast in here to gain safety.
|
|
|
|
|
|
|