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 Professional Discussion / Im stuck on this source code (Dark Principal Tutorial)

Author
Message
Wizzerd
15
Years of Service
User Offline
Joined: 25th Jan 2011
Location:
Posted: 20th Oct 2011 08:47
So Im pretty sure I followed the tutorial to the tee but for some reason it was giving me a compilation failed command out of place in like 65 and then point to line 29. I dont know what I did wrong. Please help.

This is the tutorial I was using.
http://www.youtube.com/watch?NR=1&v=e3rfBDcQmZA

Rem ***** Included Source File *****
Randomize (Timer ())
MyRandomNumber = RND(10)

Print "Numbers are between 0 and 10 you have three tries to get it right"

GameState = 0
NumberOfTries = 0

Repeat

Rem// Inc stands for increase.
Inc NumberOfTries

Select NumberOfTries

Case 1

Input "Hi! This is your first guess, good luck! ", MyGuess
If Myguess = MyRandomNumber
Print "Wow on your first go! Well Done"
GameState = 1
Else
Print "Try Again"
Endif

Case 2

Input "Hi! This is your second guess good luck! ", MyGuess
If Myguess = MyRandomNumber
Print "Wow on your first go! Well Done"
GameState = 1
Else
Print "Try Again"
Endif

Case 3

Input "Hi! This is your last guess, good luck! ", MyGuess
If Myguess = MyRandomNumber
Print "Wow on your first go! Well Done"
GameState = 1
Else
Print "Im sorry you are out of guesses, you lose"
GameState = 1

Endif

EndCase

Case Default

End Case
Print "An Error Has Occured some how number of tries is out of bounds"

EndSelect

Until = GameState=1

Print "Press Any Key To Exit Game"

End Key
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Oct 2011 14:05 Edited at: 20th Oct 2011 14:12
Made some changes. You mainly forgot the endcase separating each case and had an extra "=" in yout until line.

I added some color to the text and a subroutine that lets the player know if their guess was "too high" or "too low".
<any key> plays another game.
[ESC] exits the game.



Your signature has been erased by a mod please reduce it to 600 x 120.
Wizzerd
15
Years of Service
User Offline
Joined: 25th Jan 2011
Location:
Posted: 20th Oct 2011 23:58
when you say <any key> plays another game, you mean when they hit a key after making the decision they program will move on to the next set of instructions in that code.

for example

if 1=1

then print 1 equals one

else
Print"Try Again"

end if

any key

print "this is the next part of the program"

I was having an issue where after the <if> and <endif>
I was not able to continue to my next line but I was using <wait key> rather than <anykey>
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 21st Oct 2011 01:37 Edited at: 21st Oct 2011 01:42
I'm not sure what you are asking exaclty.
The altered code is in the '+ Code Snippet' in my previous post. Click on that and it will expand to show you the altered source.

I added a DO -> LOOP surrounding your code. I kept your wait key command. So the program waits for a key press and then hits the LOOP command, which causes the program to start executing instructions right after the DO command. Unless it's specifically disabled, DBpro programs by default close whenever the ESC key is pressed. It's not really a nice way to end a program, but I just wanted to add a quick way to replay the game.

There is no anykey command. I'm just telling the user by use of print command; to press <any key> to play again. I didn't intend to confuse you.

Your signature has been erased by a mod please reduce it to 600 x 120.
Wizzerd
15
Years of Service
User Offline
Joined: 25th Jan 2011
Location:
Posted: 22nd Oct 2011 19:51
How would I break the loop to move on to my next line of code?
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 22nd Oct 2011 20:23
Quote: "How would I break the loop to move on to my next line of code?"


post an example of what you are trying to do. And where it isn't working.

Your signature has been erased by a mod please reduce it to 600 x 120.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Oct 2011 22:30
Quote: "How would I break the loop to move on to my next line of code?"


To leave any loop (FOR/NEXT, DO/LOOP, WHILE/ENDWHILE, REPEAT/UNTIL) use the EXIT command. It'll go to the line just after the end of the loop.



Login to post a reply

Server time is: 2026-07-10 09:56:34
Your offset time is: 2026-07-10 09:56:34