Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[help] with functions #444085
07/30/14 05:20
07/30/14 05:20
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Code:
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...

laugh


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: [help] with functions [Re: DLively] #444089
07/30/14 08:09
07/30/14 08:09
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
because 'me' get's lost?
pass it to the function as pointer.


POTATO-MAN saves the day! - Random
Re: [help] with functions [Re: Kartoffel] #444097
07/30/14 10:14
07/30/14 10:14
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (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.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Originally Posted By: Superku
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 Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
THANKS GUYS laugh

Quote:
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 wink

Quote:
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 laugh

A quick read in the manual has helped me distinguish the difference between the two laugh

Again, thanks guys!


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
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 Offline
Senior Expert
Quad  Offline
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:
Quote:
#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 Offline OP
Serious User
DLively  Offline 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.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
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 Offline
Senior Expert
Quad  Offline
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 Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Thanks for your help, Quad laugh

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 laugh

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 laugh


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com

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