Can I use a variable with Goto or Gosub?

Started by cwbraue, February 03, 2017, 06:55:49 PM

Previous topic - Next topic

cwbraue

I am trying to make a middle-earth trivia game. What I was planning to do was to have a list of trivia questions and access them at random by assigning a value a random number between the first line number and last line number with questions. I figured out how to make a random number in the range of the line numbers that have the questions, but I can't figure out how to go to the line number using a variable. Is it not possible to use a variable with Goto or Gosub?

Note, I have plenty of experience with basic, but I am just starting out with playbasic.

kevin

#1
   Sounds like Select / Case block  or On Variable Goto / Gosub should do the job.  


PlayBASIC Code: [Select]
     Myoption = Rnd(5)

Select MyOption

case 0
print "My Option was #0"


case 1
print "My Option was #1"

etc etc


EndSelect






PlayBASIC Code: [Select]
     Myoption = Rnd(5)

on MyOption goto option0, option1, option2 etc etc


option0:
print "My Option was #0"
goto done


option1:
print "My Option was #1"
goto done

etc etc


Done:




cwbraue

Thank you! With your example and using the help section on Select I can now display random middle-earth trivia questions for the player to answer.

kevin


You probably should just store the anwers in an array and then look them up..