|
Too many functions
#450053
04/05/15 20:45
04/05/15 20:45
|
Joined: Apr 2015
Posts: 29 Germany
Saschaw04
OP
Newbie
|
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).
#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
OP
Newbie
|
OP
Newbie
Joined: Apr 2015
Posts: 29
Germany
|
Sorry I found the mistake. 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
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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
Last edited by 3run; 04/05/15 21:02.
|
|
|
Re: Too many functions
[Re: Saschaw04]
#450057
04/05/15 21:03
04/05/15 21:03
|
Malice
Unregistered
|
Malice
Unregistered
|
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
OP
Newbie
|
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 --
|
|
|
|