2 registered members (Ayumi, 1 invisible),
584
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[help] with functions
#444085
07/30/14 05:20
07/30/14 05:20
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
function basic_effect(var* var_num){
VECTOR effect_spot;
vec_for_vertex(effect_spot, me, var_num);
effect(wings_Effect_base, 2, effect_spot, nullvector);
return(var_num);
}
action tempact(){
while(1){wait(1);
basic_effect(21);
my.pan += 15 * time_step;
}
}
Why doesn't this work? If I just place the effect in the action, it obviously works - but not if I place it in a function...
|
|
|
Re: [help] with functions
[Re: Superku]
#444098
07/30/14 10:15
07/30/14 10:15
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
You don't want to have a var POINTER as a function argument but just a regular var, so remove the *.
The me is "transmitted" to the called function, that's not a problem. However, for a cleaner code you should use an ENTITY* pointer and replace me/ my as Kartoffel suggested. Oh I didn't know that me is passed automatically, thanks.
POTATO-MAN saves the day! - Random
|
|
|
Re: [help] with functions
[Re: Kartoffel]
#444111
07/30/14 15:53
07/30/14 15:53
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
THANKS GUYS pass it to the function as pointer. Thats a good idea - I didnt see that. Although as Superku said its not required, it will be usefull later on down the road You don't want to have a var POINTER as a function argument but just a regular var, so remove the *. Thank you! That solved it right there A quick read in the manual has helped me distinguish the difference between the two Again, thanks guys!
|
|
|
Re: [help] with functions
[Re: DLively]
#444115
07/30/14 17:22
07/30/14 17:22
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
Lite-c actually causes people to confuse the two in the long run because it has automatic pointer detection stuff, like you do not have to use & operator the get the address while passing a parameter, lite-c does that for you etc. Better use #define PRAGMA_POINTER after some point(once you are familiar with pointers) to have cleaner code(by cleaner i mean more explicit) and actually have better understanding of what you are doing. from manual: #define PRAGMA_POINTER Switches off the lite-C pointer autodetection, and treats pointers as in C/C++. The address operator (&) must be used for passing addresses to functions, and the -> operator must be used for elements of a struct pointer. Otherwise a syntax error will be issued.
Last edited by Quad; 07/30/14 17:23.
3333333333
|
|
|
Re: [help] with functions
[Re: Quad]
#444120
07/30/14 18:28
07/30/14 18:28
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
The problem with #define PRAGMA_POINTER is that it causes the includes to have pointer issues such as mtlfx.c
Furthermore, i get an issue with: vec_set(mouse_pos,mouse_cursor); (If I comment out the mtlfx.c since im not currently using it)
I'd like to indulge into this more, thus some further help with this would be appreciated.
What should I be replacing the 'comma' with to correct this error?
Last edited by DLively; 07/30/14 18:28.
|
|
|
Re: [help] with functions
[Re: DLively]
#444128
07/30/14 20:32
07/30/14 20:32
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
Okay. That's because the signature of the vec_set is:
vec_set ( VECTOR* vector1, VECTOR* vector2)
You see, vec_set expects both parameters to be VECTOR*(VECTOR pointer). But mouse_pos and mouse_cursor are defined as VECTOR and not VECTOR* in avars.h (which is included in acknex.h)
This means they are the VECTOR structs themselves and not pointers to these structs. You need pointers to these structs so you use the reference operator which is &.
&mouse_pos means "address of mouse_pos" which gives you what you need = a pointer to mouse_pos.
so you do
vec_set(&mouse_pos,&mouse_cursor);
#define PRAGMA_POINTER makes pointers in lite-c more or less work as the same way as in c/c++.
I will give you the short version but read up on pointers in C for further explanation as to why this is required or why it works this way in C:
-- I actually wrote some stuff there but i realized it was more confusing than helping without more background knowledge on C and pointers and stack and heap and how memory works. So, read up on them if you want more details. In fact do read about them, it will almost definitely be helpful in the future.
--
EDIT: not sure about the mtlfx part, it could be that it's written with the assumption that PRAGMA_POINTER is not defined.
Last edited by Quad; 07/30/14 20:33.
3333333333
|
|
|
Re: [help] with functions
[Re: Quad]
#444130
07/30/14 21:12
07/30/14 21:12
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
Thanks for your help, Quad This is a very interesting side of programming. I've got a book on my desk for c++ that I've been meaning to read I can see I am going to run into many script 'errors' on my way into this, and the current project I am working on already has 10000+ lines of code - thus I am not sure I want to experiment with this, with my project without proper knowledge or background. However, I do intend on using this method with my next project (not a clue what it is yet XD) But I'll feel safer doing it that way, rather than mucking up my current project, or losing time on it. Thanks again, friend
|
|
|
|