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 / If. . .Then Question(and some others)

Author
Message
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 10th Oct 2007 02:49
This is probably a stupid question but anyways, in an if. . then statement can you use AND like this



and if not how can I get a code to do this, if the user pushes q and a then it will play sound 1. and if i do this can the user hold down a then press q and the sound will play ONCE. then when q is pressed again it will play the sound again ONCE.

my second question
my screen flickers the text on it. i am using a print command inside a loop like this:



the screen will flicker the text instead of showing it steady

please help

jthtiger
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Oct 2007 04:37 Edited at: 10th Oct 2007 04:37
1st snippet: keystate is your friend here. Check the keystate instead of the scancode. if keystate(16)=1 and keystate(30)=1 then play sound 1

To make sure it only plays once you could use a variable to check it's status.


or you could simply check the sound if it is still playing or not.

i.e. if keystate(16)=1 and keystate(30)=1 and sound playing(1)=0 then play sound 1

2nd snippet:
I don't get why you would put something like that in a do-loop. Some questions:
1. Do you really need to clear the screen every loop?
2. Do you really need to print "mode" every loop?
3. Why not clear the screen and print it one time?
4. If you really need this in your loop, did you turn the sync on and set the sync rate at the start of the program? (i.e. sync on : sync rate 60)

LB
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 10th Oct 2007 04:53
ok i got the sounds working but about the sync. i want to display the variable value and when it is changed that printed text should update the value so the screen shows "Mode = 1" then when a user presses a key the mode variable changes to 2 then that text should read "Mode = 2" how can i do this without putting it into the loop?

thanks for the sounds help

jthtiger
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Oct 2007 06:32 Edited at: 10th Oct 2007 06:34
I would change it in the routine or code where the mode is being changed. If this is your main loop, typically what is done is it branches to other parts of your program. A limited example using procedures:



The code does not do much, but it does demonstrate how you can change the mode from within a procedure. Also, instead of clearing the whole screen, I grabbed the image underneath where the 'mode=#' will be displayed. Then before I display what the mode is, I paste the image there.

[EDIT - btw, you use the D and F keys to change to modes 2 and 3. The arrow keys move the 'player' around.]

Hope this helps.

LB
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 11th Oct 2007 06:57
ok thanks it all works now! I dont think that DB is quite fast enough to do what im thinking about but i will still probably finish the code to see. thanks again for all your help!

jthtiger
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 12th Oct 2007 03:07 Edited at: 12th Oct 2007 03:08
Quote: "I dont think that DB is quite fast enough to do what im thinking about but i will still probably finish the code to see."


This is not so!!!!!!!!

LBFN is right about the sync commands, you just hve to experiment around a little to get the number just right for your computer.

If that fails then it is your computer that is too slow, not DB, as it is your computer that is reading the code. If your computer was faster(like i said above, this is if sync commands don't work but they should), then it might match up at a unique speed. In that case, DB is too fast


Maryville Game Developers
Visit our website at http://www.freewebs.com/maryville-game-developers/index.htm
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 12th Oct 2007 16:06
jthtiger 2006

I agree with Pixelator here. DBC is reasonably fast and has been more than adequate for things that I have done. A good example of the power of DBC can be seen by looking at Starwraith's Games.

Granted, I have a fast computer, but I can't think of anything that I have wanted to do that I was unable to do because of a speed limitation within DBC.

I would suggest that perhaps your code could be optimized to speed it up. I have some more questions for you:
1. What is it exactly that you are trying to do? (please list quantities)
2. Are you checking the Frames Per Second (FPS)? [if you are unfamiliar with it, see the command 'screen fps()' ] If you are, what are you getting?

If you don't want to post your code here, you could email it to me and I would be willing to take a look at it for you. (I will keep it to myself.)

LB
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 12th Oct 2007 18:44
Quote: "DBC is reasonably fast"

So fast on some computers that you have to slow it down!

Your signature has been erased by a mod because it's larger than 600x120
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 14th Oct 2007 05:07 Edited at: 14th Oct 2007 05:12
ok im not really trying to create a "game" i am going to use my guitar hero controller as a synth instrument. like the guitar zeros and powerglove(www.vgmetal.com if you dont know who this is) they wrote some code and along with a set of notes(.wav files that held one note on a guitar)they could play their guitar hero controller and it would sound like a real guitar. i know my code is not optimized and it isn't even finished yet but ill still post it here:



there it is. it is not finished and i have all the media. if you need it i can zip it up and send it your way. thanks for the help. cuz im just not understanding C#.

jthtiger

EDIT: this is the code without the sync on but doing that still did nothing for me.
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Oct 2007 07:21
Some comments:

Why not make this


into this:


After your main loop ends you need an 'end' command, though since you have no additional way to exit the main loop, it is more for readability than anything.

Your code would be more readable if you were to indent it.

I don't see the need for checking the scancode in your mode1 procedure, but if you must keep it, why not do it like this:


I do not see any return on your mode1 procedure. You must have a return at the end of it in order for the program to go back to the instruction after it was called.

I really don't see any reason to change the mode just because a different note is played. If it were me, I would check the keystate of all of the keys involved and assign variables to them. I would then call a subroutine that would play the correct note(s) based upon the keys pressed. I wouldn't separate them out into separate procedures as you have.

I also wouldn't clear the screen every cycle myself to print two variables. You could graphically portray what keys are pressed fairly easily I would think.

Good luck,

LB
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Oct 2007 20:23
@JTiger
you're probably gonna hate me for saying this if you've already made all those sound waves, but you can get different notes from the same sound by altering its frequency (SET SOUND SPEED)

Here are the only frequencies I can find at the moment, remember that the initial frequency of your sound will effect this so it may not sound right

I made a piano on my old computer but it's busted so I can't get at the code

jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 15th Oct 2007 00:19
eh ive already done this and it really wasn't hard but ill just stick with this. thanks though.

jthtiger
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Oct 2007 00:24 Edited at: 15th Oct 2007 00:39
This:



Could be changed to:



You also need Return after all of the Mode procedures at the end. Without a return they are only labels and you would need to use Goto to get back into the main loop - definitely NOT recommended!

Also, this section can be made a little simpler:



Not a lot different to what LBFN suggests - just my way of doing it.

There's always more than one way to skin a cat...

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Oct 2007 01:32
Doing it your way actually has its advantages though; because each note has its own sound you can have multiple notes playing at the same time, and so music is born
what are you making? What are all the modes for?

jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 18th Oct 2007 05:56
i am going to use my guitar hero controller as a synth instrument. like the guitar zeros and powerglove(www.vgmetal.com if you dont know who this is) they wrote some code and along with a set of notes(.wav files that held one note on a guitar)they could play their guitar hero controller and it would sound like a real guitar. the modes are for the different note sets. if you don't know a guitar hero controller has 5 fret buttons, a strum bar, and a start and select button. i am using the keyboard to switch between say the C major note set and the D note set and so on. and the start and select button will change some notes too. so here is an example of mode 1

MODE 1:
SMODE 1:
1st fret plays Low C
2nd fret plays E
3rd fret plays G
4th fret plays B
5th fret plays High C

SMODE 2:
1st fret plays Low C
2nd fret plays D
3rd fret plays F
4th fret plays A
5th fret plays High C

Start and Select switches SMODE

make sense?

jthtiger
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 19th Oct 2007 06:31
btw i checked my FPS and my average is 32. it should be good but it is still a little flashy.

does anyone know of a better way do make this kind of app using db?

jthtiger
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 00:26
@TDK

I actually do have a RETURN in the mode1 label



this seems to be working so that when im in the mode1 loop if i press a number key it will quickly go to the main loop and then the main loop will pick it up and go to the next mode. i think it is working ok. i just wish i could get the sounds to play faster there is like a 250 ms delay between when you push the button and the sound acutally playing. i have an idea though that i may try. i think it is my sound file. it may have a little delay at the start. if that is not it though any suggestions?

jthtiger

P.S. thank you guys for all your help so far
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Oct 2007 00:43
@JTiger

If you do the same thing more than twice there's probably a better way of doing it

@probably TDK
Can you do the above this way in DB?


jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 00:58 Edited at: 21st Oct 2007 02:13
@OBese87

for some reason that wont work for my because when im in the middle of the mode1 label and doing something it jumps back to the main loop. Maybe because im pressing other keys inside of mode 1 and it may be doing something to it but im not sure. The way i have it seems to be working fine so i think ill stick with it but thanks for the input.

EDIT: I have updated the code:



ok i can't figure this out. i want to have the prog play a sound when 1 "fret" is pressed. but if 2 "frets" are pressed i want it to play 2 sounds. so i have this part in there



but even though i have the green and red frets pressed down it only plays the green sound(Lowest C) and help?

@Pixelator

ok i have a custom built computer with a AMD Athlon 64 X2 Dual Core Precessor 3800+ 2.01 GHz with 2 GB of RAM and 2 NVIDIA DeFore 7800 GTX Graphics cards bridged with Sli mode. I dont think my computer is too slow for this.

jthtiger
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Oct 2007 10:29
Quote: "if 3 <= scancode() <= 11 then RETURN"


It works, but that doesn't mean it's a good method to use.

Return is an end marker for a block of code. The block happens to be a procedure and there should really only be one Return - at the very end.

jthtiger 2006

I think that your main cause for problems is the fact that you have more than one main Do..Loop. The second one is forcing you to do things in a non-standard way.

The Mode1 section of code (like all the others) should really be a procedure with a single Return at the end.

If you need to trap the PC in a procedure, then use a conditional loop like Repeat..Until so you can drop out of it to get to the Return. Along the lines of:



I've modified the first half of the Mode1 procedure - you just need to add the second half yourself (and all the others). Notice I've dropped all those # symbols. These define float variables and all you are using is integers (which incidentally are much faster).

It's a pain at first, but if you get the hang of program structure early on, it will save you many hours of frustration later on.

Indenting your code will help us as well as you follow the program flow too!

TDK_Man

jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 11:32
ok here is the updated code



if i did not indent right please tell me.
now the part where it says


that still does not work for me. for some reason it wont stay in the mode 1 procedure. i press the 1 key but as soon as i release it it goes back to the main loop. this is not what i want. i want to be able to press the 1 key then inside of the mode1 procedure if i happen to press another number key then it goes back to the main loop and onto the mode indicated by the number i press. have any ideas?

thanks again for all your help so far

jthtiger
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 21st Oct 2007 12:30 Edited at: 21st Oct 2007 19:05
you want

not or.

and could you not just set a variable as modevar and then in your main loop say
or whatever

http://jamesmason01.googlepages.com/index.htm
jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 16:02
thats what i had thought at first but now ill go to the mode and after i play one sound it jumps back to the main loop and then starts the jumping back and forth thing again.

jthtiger
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Oct 2007 22:22
Quote: "you want

if scancode() > 2 and scancode() < 12 then modeexit = 1

not or."


My apologies for the typo - I entered the code snippet directly into the forum message box at 8:30 in the morning (after an all night programming session) so I'm surprised there weren't more errors!

It should indeed be 'And'. So, if the user presses any key with a scancode between 3 and 11 program control drops out of the loop in Mode1 and returns to the main program loop.

Any other key and it drops through and continues around the Mode1 loop doing whatever is there.

TDK_Man

jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 22:32
see that works but only if i HOLD down the 1 key if i release it it goes back to the main loop. i need to be able to press the 1 key and it goes to the main loop and without holding it down be able to play some notes and if i hit 2 it drops out and essentially goes to mode 2. maybe i should put in something that instead of dropping out it goes to the other mode like this



that way instead of dropping out of mode 1 when 2 is pressed it goes directly to mode 2 instead.

jthtiger
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Oct 2007 22:53
First of all, where are the missing Returns for the rest of the Mode procedures? Remember, without them, they are only labels.

Secondly, the biggest problem is that without the sounds, we can't actually run the program to see ourselves if what we are suggesting fixes the problems - so bear with us!

I think the problem is most probably due to two things: keys being held down too long and not clearing out variables.

For example, when you press say the 2 key, DB is so quick that it's in the procedure before you've let go of it. It then thinks that you want to exit back to the main loop.

If you press the 2 key again, when you get to the correct Mode procedure, ModeExit is still set to 1, so it immediately exits...

Try this version (indented with my DBA Tidy program) by the way...



TDK_Man

jthtiger 2006
19
Years of Service
User Offline
Joined: 11th Mar 2006
Location: Somewherein the U.S.
Posted: 21st Oct 2007 23:12
ok now it works. . .sort of. it will play a few sounds and then jumps back to the main loop. i have one more thing to try first and ill see if it works but in the mean time i have zipped up the sounds and i included them in this post.

i sincerely thank you for your patience and help

jthtiger

Attachments

Login to view attachments
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Oct 2007 07:24
Oops - just spotted a # I didn't remove.

In the setup there's the line mode# = 0. It's not that important but it should be mode = 0.

TDK_Man

stuthemoo
17
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 29th Dec 2007 05:37
jthtiger 2006


I NEED you!
PLEASE contact me!

Stuart.

Skateboarding is not a crime, (unless your doing it while carrying a conceled weapon)

Login to post a reply

Server time is: 2025-05-31 21:10:19
Your offset time is: 2025-05-31 21:10:19