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.

Newcomers DBPro Corner / Problem with a little quiz game i am trying to make

Author
Message
Zuluguy
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 5th Aug 2009 04:29 Edited at: 7th Aug 2009 14:44
Hello. well the title mainly says it all..
I am trying to make a small quiz game but i cant figure out why the Goto command wont work..please can someone tell me if i am doing it wrong or not, thanks a bunch



Also sorry but it is not very neat code lol

Print "ok here is your first question"
wait 1000
cls
print "what colour rhymes with poo?"
wait 3000
cls
Input "Is your answer Blue or green (B/G)?",Answer$
Answer$=Lower$(Answer$)
Answer$=Left$(Answer$,1)
CLS
IF Answer$="b"
Print "Congrats you win this round!"
wait 3000
print "press any key to go to round 2"
Goto Round 2:
Else
Print "Sorry Champ maybe you will have better luck next time"
wait 2000
Print "Press any key to exit"
endif
Wait key

Round 2:
Print "Great you have made it this far it would be a shame if you cant make it to the end."
wait 1000
print " ok here we go... Who is the current Prime minister in England?"
Input "Is it Tony Blair or Gordan Brown(T/G)?",Answer1$
Answer1$=Lower$(Answer1$)
Answer1$=Right$(Answer1,1)
Cls
If Answer1$="g"
print "Wooooo you did it. your now on round 3"
wait 1000
Print "press any Key to go to round 3"
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 5th Aug 2009 14:55
I'm not certain, but I don't think you're allowed to put spaces into label names.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 5th Aug 2009 15:59
Try Round_2: instead of Round 2:

Also, there seems to be a bit of a dislike for the goto command as it messes up your code. You should try to use gosub as often as possible =)

Monk

I like work. It fascinates me. I sit and look at it for hours.
Zuluguy
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 5th Aug 2009 18:34 Edited at: 6th Aug 2009 17:07
Ah yes thank you this has sorted my problem out it now actuelly goes to where i want it

Cheers Monk and PRoF
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 5th Aug 2009 19:09
Instead of using GOTO to get to the next question, try inputting all the questions and answers into an array, so the next question can be obtained by increasing a number.

Zuluguy
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 5th Aug 2009 20:00
I would try to use arrays but i do not fully understand how they work. i first had the idea for the game while i was looking at the arrays tutorial in the tutorial section. But i did not understand them. I thought i could run the game based on the section at the bottem of the example. Then i remembred about the Goto command so i tried to implement that into the quiz. At first it did not work, but when Monk and PRoF helped me with the Goto command it worked.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Aug 2009 07:53
Now that you learned how to properly use GOTO lets try to avoid it.

As Deego pointed out you really should use arrays. They allow you to use the same commands to show all questions in the array in order. For a quiz game I'd use a multi-dimensional array to store the question, choices, and answer since they're all strings.



This stores 101 sets of questions, choices, and answers (counting zero).

Here's the breakdown of what the array will store:


You can define the array at the top of your code (after the dim statement):


So if you want to know what the answer is for the first question you look at Question$(0,2) or the choices of question 2 you look at Question$(1,1).

To go through all the questions you can use a FOR/NEXT loop which basically makes a variable equal a number range that it adds to or subtracts from every time it loops.



This is a FOR/NEXT loop that makes t=0 the first time it goes through the loop, then t=1 the second time, then t=2 the third time... once it hits the end of the FOR/NEXT loop it goes on to the next line under NEXT t.

Because all the questions and answers are in the array you can use a single IF/ENDIF statement to check every single answer (one answer per loop of the FOR/NEXT).



This checks if Answer$ is equal to Question$(t,2) so the first time it goes through the FOR/NEXT loop it's checking if Answer$=Question$(0,2) which is "b". The third time it's looking at Question$(2,2) which is "g".

Here's everything above combined:


Zuluguy
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 6th Aug 2009 16:59 Edited at: 6th Aug 2009 17:50
-EDIT-

Dont worry about this question i ffigured it out.
Zuluguy
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 6th Aug 2009 17:30 Edited at: 7th Aug 2009 14:43
Ok using an array helped because its smaller and neater. But how would i end it after the last question because it is still following the for/next loop. Trying to go to the next question, but there is not another question.

Login to post a reply

Server time is: 2024-11-25 04:22:28
Your offset time is: 2024-11-25 04:22:28