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.

DarkBASIC Discussion / Am I doing something wrong?

Author
Message
Dexus 136
16
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 9th Mar 2009 03:22
I am trying to get this correct and I don't know how to do it. The way this is supposed to work is that when you push the space bar ten times it kills the enemy, but instead it keeps doing it as only one.
Here's the code -

Attachments

Login to view attachments
Gosub
17
Years of Service
User Offline
Joined: 23rd Sep 2007
Location:
Posted: 9th Mar 2009 15:37
Well I think this is more or less like your original game, hopefully you'll be able to relate the changes i've made back to your original work.

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 15:44 Edited at: 9th Mar 2009 15:47
thats because there isn't a switch.


when you press the spacebar it runs the code many many many times a second (if you want to see then put Text 0,0,Str$(Screen fps()) in there) so its doing it ten times just very very fast what you need to do is in the if for the spacebar check if a variable.... lets call it hold is =1 if not then do your code. in you code set it to one and have another if saying if spacekey()=0 then hold=0 see? lol i hope that makes sense


Other guy(don't remember yuour name):

he is still going to have the imidiate effect like he did before.


Both of you:

one word....

INDENTION

hahhahaha
Gosub
17
Years of Service
User Offline
Joined: 23rd Sep 2007
Location:
Posted: 9th Mar 2009 16:38
Quote: "he is still going to have the imidiate effect like he did before."


No he isn't, look at my code above Shreck.
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 9th Mar 2009 17:23 Edited at: 9th Mar 2009 17:26
Caleb's right, you'll need some kind of switch.

This example uses a flag variable when checking the SpaceKey. The variable is "KeyPress" by default it's Zero. When Space is pressed it makes a check, if it's Zero then proceed(subtract Life), then right after "KeyPress" is flaged = 1. The next time it loops around, "KeyPress" is 1 so it does nothing. When you let off Space then "KeyPress" returns to 0.

Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 17:36
good example LOL the only example I could think of was essentialy what you did but in my head it sounded to much like l his LOL I didn't want to give him codehe can just plug into his code but good job ashinga
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 9th Mar 2009 17:44
If you are feeling lazy, you can also use a:

Repeat
Until spacekey()=0


Less finesse but still effective.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 9th Mar 2009 22:33
Aren't you able to use pressed like with the mouse?



~QJ
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Mar 2009 03:40
Yeah, but the problem is that if you don't have something that will stop it from happening AGAIN on the same mouseclick, then it will seem immediate.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Gosub
17
Years of Service
User Offline
Joined: 23rd Sep 2007
Location:
Posted: 10th Mar 2009 12:23
You're telling me this doesn't work?
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 10th Mar 2009 16:45 Edited at: 10th Mar 2009 16:45
@Gosub
If you hold onto Space then the Enemy just keep on droping. When you tap on Space the Enemy will drop 2-4 points at a time. If your computer is fast enought one tap on Space will drop all 10 points on the Enemy.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Mar 2009 17:29 Edited at: 10th Mar 2009 17:39
when you press the space bar it checks if its pressed then subtracts the enemylife then it goes on to the next loop. does it again(if you didn't let go of the spacekey) and so if you hold it it won't stop doing it lol.





try that just hold down space and see what happens


now try that.
Dexus 136
16
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 10th Mar 2009 23:21
Thanks Caleb1994 and Ashingda 27! I believe you guys explained what really went wrong with what I did the best. ( Caleb1994: I will try to get some indents in more of my coding next time ^-^ )
So you guys are saying that I don't have anything from keeping it to loop right back to where the space key is flagged? Would either changing the sync rate or putting in a sleep command work out in there?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 11th Mar 2009 01:01
no this should be ur loop:



i made that off memory so dont be surprised if i overlooked something obvious
Dexus 136
16
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 11th Mar 2009 01:03
After working with the codes you guys provided and adding a few extras. I pulled together an actually fun game.
Check for yourselves
Dexus 136
16
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 11th Mar 2009 01:06
I just started to work on the media files for it, so the final product shouldn't take too long.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 11th Mar 2009 02:02
good job keep up the good work! Yay Indention hahaha
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 11th Mar 2009 02:03
Wow suprisingly that was really fun, gave me a good laugh!
Dexus 136
16
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 15th Mar 2009 06:16
well I am stuck on media to do for this, but I did manage to make a working Health bar system. I am having trouble making a time bar though; it just wont appear for some reason!
anyway here's the game with the health bars and the messed up time bar

I'll be back on tomorrow. I gotta go to bed.

Login to post a reply

Server time is: 2025-05-16 20:38:42
Your offset time is: 2025-05-16 20:38:42