Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, degenerate_762), 907 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: beginner problem with loops [Re: Kartoffel] #449995
04/04/15 13:38
04/04/15 13:38
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Cool, I like how you accomplished this task Kartoffel.


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: beginner problem with loops [Re: Kartoffel] #450005
04/04/15 15:49
04/04/15 15:49
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Quote:

Das ist dann auch das Problem. Damit wird nämlich die Funktion jeden frame gestartet so lange du die F-Taste gedrückt hältst. Deswegen läuft die countdown-funktion mehrmals parallel, was dann dazu führt dass der counter viel schneller und unregelmäßig runterzählt.


1. Ich halte die F-Taste garnicht gedrückt.
2. Derselbe Countdown läuft in einem anderen Script perfekt, aber sobald ich ihn in mein anderes Skript (in eine SPieler-Aktion) reinpacke läuft der Countdown wieder schneller.

Im Prinzip funktioniert ja alles => Es leuchtet wenn man F drückt und hört automatisch auf. Nur der Countdown läuft komischerweise zu schnell


-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: beginner problem with loops [Re: Saschaw04] #450006
04/04/15 16:20
04/04/15 16:20

M
Malice
Unregistered
Malice
Unregistered
M



@Saschaw04
Would you please post you current script..

Re: beginner problem with loops [Re: Saschaw04] #450007
04/04/15 16:21
04/04/15 16:21
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
mach mal den test und schau wie lang die flashlight in beiden situationen an ist:
- halte die f taste die ganze zeit gedrückt
- drück die f taste so kurz wie's geht

wenn du nen unterschied bemerkst ist es genau der fehler auf den ich hinaus will, wenn nicht ist es irgendwas anderes..

Edit: alternativ kannst du auch die anzahl an ausgeführten funktionen im debug panel anschaun

Last edited by Kartoffel; 04/04/15 16:25.

POTATO-MAN saves the day! - Random
Re: beginner problem with loops [Re: Kartoffel] #450008
04/04/15 16:24
04/04/15 16:24
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
@Kartoffel Du hast recht. Hält man es gedrückt dann läuft es sehr schnell, aber
trotzdem fragen ich mich wieso es in dem anderen Skript perfekt (300 Sekunden) läuft und sobald ich es in die aktion packe nicht mehr


-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: beginner problem with loops [Re: Saschaw04] #450009
04/04/15 16:27
04/04/15 16:27
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Here is the complete code. Maybe it helps

#include <acknex.h>
#include <default.c>


ENTITY* player1;
var counter_timer = 300;

function camera_follow(ENTITY* ent){
while(1){
vec_set(camera.x, vector(-130 ,0 , 110));
vec_rotate(camera.x,ent.pan);
vec_add(camera.x,ent.x);
wait(1);
}
}


void count_down(){
my.ambient = 100;
my.lightrange = 150;
// while we still have to count down:
while(counter_timer > 0){


// count down each second:
counter_timer -= time_step / 16;

wait(1);
}
my.ambient = 0;
my.lightrange = 0;

}

function battery(){
counter_timer = 300;
}




action drive(){
player1 = me;

while(1){ // ALLES SOLL FORTLAUFEND PASSIEREN
camera_follow(me);
if(key_f) count_down();
// Neige die Kamera nach unten
if(key_b) battery();

if(key_w){ //Wenn die W-Taste gedrückt wird, bewegt sich das Auto eine Einheit nach vorne
c_move(me, vector(6*time_step, 0, 0), nullvector, GLIDE);
}
if(key_a){ //Wenn die A-Taste gedrückt wird, neigt sich das Auto nach links
camera.pan += 0.5;
}
if(key_d){ //Wenn die D-Taste gedrückt wird, neigt sich das Auto nach rechts
camera.pan -= 0.5;
}
if(key_s){ //Wenn die S-Taste gedrückt wird, bewegt sich das Auto rückwärts
my.x -= 20 * time_step;
}
wait(1);
}
}


function main(){
// video_screen = 1;
level_load ("testlevel.wmb"); // Lade das Level "Testlevel"
camera.tilt = -34;
}

Without commentaries

Last edited by Saschaw04; 04/04/15 16:41.

-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: beginner problem with loops [Re: Saschaw04] #450010
04/04/15 16:28
04/04/15 16:28
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
das problem is da wo du die funktion aufrufst.

wahrscheinlich verwendest du 'ne while die permanent durchläuft mit nem if(..) zum checken der taste.
d.h. solang du auf der taste bist, wird jeden frame (bei normalem fps-cap alle 16ms bzw. 60 mal in der sekunde) die funktion aufgerufen weil die while schleife weiterläuft.

mit der methode die ich vorhin gepostet hab tritt das aber nicht auf, weil ich die toggle-funktion über ein event beim drücken der taste ausführe


POTATO-MAN saves the day! - Random
Re: beginner problem with loops [Re: Kartoffel] #450012
04/04/15 16:33
04/04/15 16:33

M
Malice
Unregistered
Malice
Unregistered
M



Yup Key_lock var will fix that.
Code:
var KEY_F_LOCKEDO_OR_OPEN = 0
if(!key_f && KEY_F_LOCKED_OR_OPEN == 1)
KEY_F_LOCKED_OR_OPEN =0;
IF(key_f && KEY_F_LOCKED_OR_OPEN ==0)
{
 KEY_F_LOCKED_OR_OPEN = 1;
 .... CALL FLASHLIGHT/TIMER HERE...
}

void count_down(){
my.ambient = 100;
my.lightrange = 150;
// while we still have to count down:
while(counter_timer > 0 && key_f) // CHANGED
{

// DEBUG_VAR(counter_timer, 10);

// count down each second:
counter_timer -= time_step / 16;

wait(1);
}
my.ambient = 0;
my.lightrange = 0;

}


Last edited by Malice; 04/04/15 16:39.
Re: beginner problem with loops [Re: Kartoffel] #450013
04/04/15 16:33
04/04/15 16:33
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Kann man meinen Code etwas abändern sodass es funktioniert. Deine Lösung ist zwar besser, aber ich bin noch Anfänger und möchte eine Lösung nehmen, die ich selbst auch verstehe.

Quote:
wahrscheinlich verwendest du 'ne while die permanent durchläuft mit nem if(..) zum checken der taste.
d.h. solang du auf der taste bist, wird jeden frame (bei normalem fps-cap alle 16ms bzw. 60 mal in der sekunde) die funktion aufgerufen weil die while schleife weiterläuft.

OK das Problem hab ich jetzt glaub ich verstanden.

Last edited by Saschaw04; 04/04/15 16:37.

-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Re: beginner problem with loops [Re: Saschaw04] #450015
04/04/15 17:23
04/04/15 17:23
Joined: Apr 2015
Posts: 29
Germany
Saschaw04 Offline OP
Newbie
Saschaw04  Offline OP
Newbie

Joined: Apr 2015
Posts: 29
Germany
Thank you smile
It works grin

I took the code from Malice and Change the while Loop a bit, because I wanted that the light is on after I press f and not press f all the time.


-- started with programming on march 2015 --
-- living in Germany near Dortmund --
Page 2 of 3 1 2 3

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