Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Oct 2013 16:38
How could I make a timer? I have a sprite that have a special power that should end after 5 seconds, how could I do this? I have tried to make my own timer, but then the game starts to freeze in 5 seconds. Could anyone help me??

Thanks for help

Here is my timer code

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Oct 2013 19:44 Edited at: 19th Oct 2013 19:17
First of all, a single condition can execute multiple commands:


Second, you don't actually need to check that TimeLeft>0 because your repeat-until loop is going to exit once TimeLeft=0.
(I'd actually change the exit condition to TimeLeft<=0 just in case the loop doesn't catch TimeLeft exactly at 0 seconds.)
For the same reason the condition after the loop isn't required.
Also, there's no reason to change the sync rate, let's drop the endif since the opening IF isn't visible here.


We still haven't the problem though, and that's because you're doing it all wrong.

Let's make Badass Mode activate for 5 seconds and have a ten second cool-down.

I think that works.
It's by no means a perfect solution, it's a bit messy actually, maybe you can improve on it once you learn more. Good luck.


Formerly OBese87.
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Oct 2013 20:23 Edited at: 17th Oct 2013 20:34
Thanks you for your help

Quote: "there's no reason to change the sync rate"


my idea was that badass mode should go inn slow motion, therefore I have experimenting with the sync rate. The sync rate are 66 in the code above,but it's a fail from my side. The sync rate should originally been 14.

My other thing is that I have forgotten to say that badass mode can only be activate if the player has press down three keys consecutively (space+r+t).After the player has press down the three keys, the badass mode will be activated, and end after 5-10 seconds.

Thanks again I could post my badass keys combination code afterwards
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Oct 2013 21:37 Edited at: 17th Oct 2013 21:39
Here is my code



If you could tell me how I implement your code with this code, that would be nice
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Oct 2013 22:46 Edited at: 18th Oct 2013 08:47
I figured it out self but could you improve it, so the transition between badass mode and normal mode will be smoother?

Here is my whole game code (NB it's not finished)


Thanks for answer
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 19th Oct 2013 20:33 Edited at: 19th Oct 2013 20:35
You can give your code snippets syntax highlighting by adding lang=dbp to the open tag, like this: {code lang=dbp}, but with square brackets of course.

Conditions can execute multiple commands:


Incrementing a variable like this causes problems, which you've discovered and fixed by resetting the value each loop unless all three are pressed, but it would be better to find a different approach that doesn't cause problems.

Here's a possibility, we add up the state of each key instead of incrementing

Better, but we're still looking at each key state twice which seems a bit dumb. Let's see if we can get it down to one look.

If we give the key states binary values we can add them together without losing any data, we will be able to tell from the value of state2 which keys are being pressed.

There may be more code than before but the computer is doing less work, and we also improved the output so we don't get any text starting with '+'.


Formerly OBese87.
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 19th Oct 2013 22:07
Thanks again Libervurto I will test your improvements as soon as possible.
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 19th Oct 2013 22:27
I don't know, but it seems like if I only press down T then the game start immediately badass mode, and space and R are useless. But a positiv thing is that my game did not freeze anymore (the transition between badass mode, and normal mode



Thanks again for help

Login to post a reply

Server time is: 2025-05-15 20:44:45
Your offset time is: 2025-05-15 20:44:45