0

I'm working on a number guessing game in Small Basic. A number range from 1 to a self-selected number is created. There are multiple rounds and everything works in the first round. But not from the 2nd round, because the generated number is taken from the 1st round.

The code looks like this:

Sub Random z = Math.GetRandomNumber(hz) EndSub

z is the automatically generated number and hz is the highest number, i.e. H. how far you can guess.

Is there a command I can use to "reset" the variable so that a new number is generated in the 2nd round?

1 Answers1

0

The variable z does not have to be reset. The Random subprogram only has to be called each time a new round is started. This can be verified with the following TextWindow output:

Sub Random
  z = Math.GetRandomNumber(hz) 
  TextWindow.WriteLine( "z = " + z + "  hz = " + hz )
EndSub

Note: There is a Hi-Lo game and many other small games (only for Textwindow) in the book Basic Computer Games (Small Basic Edition) by Philip Conrod.

Scout
  • 41
  • 1
  • 1