Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
3 registered members (7th_zorro, henrybane, AndrewAMD), 1,343 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Too many functions #450053
04/05/15 20:45
04/05/15 20:45
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Hello everybody,

I have a Problem with my script. If I start the game, the Count of functions rises until it reachs a Point where I get an error "Too many functions" (after 1-2 minutes).

Code:
#define STATE skill1
#define CREATOR skill2
#define ANIMATION skill3

ENTITY* spieler;
ENTITY* zauber;
ENTITY* feind;

function camera_follow(ENTITY* ent)                 //Dritte Person Kamera

 { 
    while(1) { 
      vec_set(camera.x,vector(-150,10,25)); 
      vec_rotate(camera.x,ent.pan);
      vec_add(camera.x,ent.x);
      vec_set(camera.pan,vector(ent.pan,-10,0)); 
      wait(5); 
    } 
 } 
 
 function sterben(){
 	my.ANIMATION = 0;
 	my.STATE = 4;
 	}
 


action zauberkugel()
{

zauber = me;
my.pan = your.pan;
my.ambient = 50;
my.lightrange = 300;
vec_set(my.blue,vector(255,50,50)); // bluish light color
set(me,BRIGHT);   // additive blending
vec_scale(my.scale_x,0.15);
c_setminmax(me);

set(my, FLAG2);
my.CREATOR = you;
my.STATE = 1;
//////////STATE 1 == FLIEGEN////////////////////////////////////////////////////////////
while(1){	
if(my.STATE == 1){
c_move(me, vector(40*time_step, 0, 0), nullvector, IGNORE_YOU); //IGNORE _YOU verhindert dass die Kugel schon mit dem Spieler kollidiert
my.roll += 20*time_step;

if(HIT_TARGET) my.STATE = 2;
}
//////////STATE 2 == KOLLISION////////////////////////////////////////////////////////////////
if(my.STATE == 2){
set(me,ZNEAR);         //ZNEAR sorgt dafür, dass das Explosionssprite komplett sichtbar ist
my.roll = random(360);       //Der Roll-Winkel wird jedem Frame auf einen Zufallswert von 0 bis 360 Grad gesetzt
my.lightrange= my.lightrange* (1+0.5*time_step);   //Lichtkegel wächst exponentiell an (mit jedem Tick)
vec_scale(my.scale_x,1+0.5*time_step);     //Größe des Sprite wächst exponentiell an (mit jedem Tick)
if (my.scale_x > 1) {                       //wenn Originalgröße erreicht, dann entferne Sprite
ent_remove(me);
return;	                     //Macht Entfernen des Sprite rückgängig	
}
wait(1);
}wait(1);
}
}

action gegner(){
	feind = me;
	my.event = sterben;
	my.emask |= ENABLE_IMPACT;
	ENTITY* enemy = NULL; //Zauberziel
	my.STATE = 1;
	while(1){
	//////////////STATE 1 = NICHTS TUN//////////////////////////
	if(my.STATE == 1){
		c_scan(my.x, my.pan, vector(360, 0, 750), SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
		if(you) {  //Spieler oder Zauberkugel gefunden?
	   my.STATE = 2;	
		enemy = your.CREATOR;
	}
	}
	//////////////STATE 2 = ANGREIFEN/////////////////////////////////
	if(my.STATE == 2){
		VECTOR vDirection;
		ANGLE vTargetAngle;
		vec_diff(vDirection, enemy.x, my.x);
		vec_to_angle(vTargetAngle, vDirection);
		my.pan += time_step* sign(ang(vTargetAngle.pan - my.pan));
		
		my.ANIMATION += 3*time_step;
		ent_animate(me, "attack", my.ANIMATION, ANM_CYCLE);
		if(my.ANIMATION>100){
			ent_create("spell.dds", vector(my.x,my.y,my.z+10), zauberkugel);/////////STATE 3 gibt es nicht
			my.ANIMATION -= 100;	
		}
	}
	/////////////////STATE 4 = STERBEN//////////////////////////////
		if(my.STATE == 4){
		my.ANIMATION = 3*time_step;
		ent_animate(me, "death", my.ANIMATION, 0);	
		if(my.ANIMATION>70) 
		return;
		}
	wait(1);	
	}
}

action move(){
 spieler = me;
 my.STATE = 1;
 VECTOR vFeet;
 vec_for_min(vFeet,me);
 
 my.event = sterben;
 my.emask |= ENABLE_IMPACT;
 set(my, FLAG2);
 my.CREATOR = me;
 
 while(1){         // ALLES SOLL FORTLAUFEND PASSIEREN
 camera_follow(me);      //Kamera soll Spieler folgen	
 c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
 my.z = hit.z - vFeet.z;
 
 /////STATE 1 == LAUFEN///////////////////////////////////////
 if(my.STATE == 1){
 var walk_speed;
 walk_speed = (key_cuu-key_cud)*5*time_step;
 c_move(me, vector(walk_speed, 0, 0), vector(0, 0, 0), GLIDE);
 my.pan += (key_cul-key_cur)*5*time_step;
 
 my.ANIMATION += walk_speed*2;
 ent_animate(me, "walk", my.ANIMATION, ANM_CYCLE);
 if(my.ANIMATION>100) my.ANIMATION -= 100;
 if(key_space){                                            ///Wird die Leertaste gedrückt, dann gehe über in Zustand 2
 	my.STATE = 2;
 	my.ANIMATION = 0;
 	}
 }
 ////////STATE 2 == ANGREIFEN/////////////////////////////////
 if(my.STATE == 2){
 
 my.ANIMATION += 8*time_step;	
 ent_animate(me, "attack", my.ANIMATION, 0);
 if(my.ANIMATION>=100){                              //Ist die Animation einmal abgespielt worden, dann setze sie zurück und gehe über in Zustand 3
 	 my.ANIMATION = 0;
    ent_create("spell.dds", vector(my.x,my.y,my.z+20), zauberkugel);
 	 my.STATE = 3;
 	 }
 	}
////////STATE 3 //////////////////////////////////////
if(my.STATE == 3){
	if(key_space != 1){                                       //Ist die Leertaste losgelassen, wenn ja, gehe zurück in Zustand 1
	my.STATE = 1;		
	}	
}
//////////STATE 4 == STERBEN//////////////////////////////////////////
if(my.STATE == 4){
	my.ANIMATION = 5*time_step;
	ent_animate(me, "death", my.ANIMATION, 0);
	if(my.ANIMATION>70){
		return;
	}
}

wait(1);
}	

}



I suppose that it has something to do with while(1) Loops.
And yes, this is the try to make the Workshop 24

(This .c data is part of another scipts. Thats why function main is missing)

Last edited by Saschaw04; 04/05/15 20:55.

-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: Too many functions [Re: Saschaw04] #450054
04/05/15 20:59
04/05/15 20:59
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Sorry I found the mistake.

grin Function in a while Loop and in the function is a while Loop too

Last edited by Saschaw04; 04/05/15 20:59.

-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: Too many functions [Re: Saschaw04] #450055
04/05/15 21:01
04/05/15 21:01
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Saschaw04
Code:
function camera_follow(ENTITY* ent)                 //Dritte Person Kamera

 { 
    while(1) { 

      wait(5); 
    } 
 } 
 
action move(){
  
 while(1){         // ALLES SOLL FORTLAUFEND PASSIEREN
 camera_follow(me);      //Kamera soll Spieler folgen	
 

wait(1);
}	

}

You need to go throw your code and make sure, that you don't put function with LOOP inside of the other LOOP (in another function). Here f.e. you you call 'camera_follow(me);' inside of the 'move' action's LOOP. This will lead to increasing functions and to the error you've faced. To avoid this, you need to call 'camera_follow(me);' outside of the LOOP (right before it!), so you won't run function with it's own LOOP each frame. This is pretty tricky at the start, but very easy when you'll understand everything on practice!


Edit: too late, but well, nice to see that you've found it yourself laugh

Last edited by 3run; 04/05/15 21:02.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Too many functions [Re: Saschaw04] #450057
04/05/15 21:03
04/05/15 21:03

M
Malice
Unregistered
Malice
Unregistered
M



Camera_follow is a infinite loop that you are calling inside an infinite loop. Don't do that. Remove the WHILE from camera_follow.

EDIT : Dang it I'm late also

Last edited by Malice; 04/05/15 21:04.
Re: Too many functions [Re: 3run] #450058
04/05/15 21:05
04/05/15 21:05
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
This is the classical mistake of a beginner
==> I hope other beginner see it and learn from it.

PS: it is good to know that you can see see Count of function if you press F11.
On this way I saw the reason of the bug.


-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: Too many functions [Re: Saschaw04] #450060
04/05/15 21:08
04/05/15 21:08
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Saschaw04
This is the classical mistake of a beginner
==> I hope other beginner see it and learn from it.

PS: it is good to know that you can see see Count of function if you press F11.
On this way I saw the reason of the bug.
Yes! That's how I've learned too. I remember when I first faced this problem back in 2009 grin But probably newbies won't learn from your experience, at least most of them, cause they mostly learn on their own mistakes, almost all of us did when we just started grin


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Too many functions [Re: 3run] #450074
04/06/15 09:57
04/06/15 09:57
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Not only when we started, I just did it two days ago in my MP tutorial grin Good thing some of the errors are self-explaining.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

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