Hi,
don't give up! You're asking the right questions and all the info you need is here. Forget about local variables for the time being, they may be confusing the issue at the moment.
Take a break; read a book, watch telly, listen to some music, do something that will take your mind of this and when you come back it will be clearer.
I don't want to give too much help because if you can figure this out for yourself you'll certainly remember it.
For the time being I'll recap the structure of a subroutine:
sub Example()
sub Example(Parameter1)
sub Example(Parameter1, Parameter2$)
1. The command
sub tells Yabasic to expect a subroutine with the name immediately following it and continuing until the open bracket.
2. All parameters must be inside the brackets. There is no limit to the number of params allowed and passing zero params is perfectly fine.
sub Double(Param1)
Param1 = Param1 * 2
...
Inside the subroutine you can do whatever calculations or printing or inputting or drawing etc to make the sub do what it should.
sub Double(Param1)
Param1 = Param1 * 2
return Param1
Returning a value from a subroutine is not obligatory but it is a useful aspect of these things that make it one of the more powerful parts of Yabasic.
sub Double(Param1)
Param1 = Param1 * 2
return Param1
end sub
All
end sub does is tell Yabasic that the subroutine definition has finished.
Now, if I wanted to use a subroutine in a script I would do something like this:
clear screen
Print "I'll think of a number between one and ten and you have three goes at guessing what it is."
target = int (ran (10) + 1)
try = 0
Complete = False
repeat
try = try + 1
print "Try number ", try
input "Have a guess... " guess
Complete = is_guess_correct(guess, target)
until (try = 3 or Complete = True)
if Complete = False then
print "Bad luck... The number you wanted was ", target
else
print "Well done..."
end if
sub is_guess_correct(first_number, second_number)
if first_number = second_number then
return True
else
return False
end if
end sub
This is a little guessing game that uses a subroutine to test if the player has guessed the correct number and I'm putting it here because it is a complete script that may help.
While using subroutines is like creating your own commands or functions they have to stick with the same basic structure.
Derek.