Post by johnno56 on Jun 22, 2021 18:02:24 GMT -6
This may sound trivial, but I have concerns about the 'mid()' command.
Back story. Simple conversion of Mastermind from one Basic to RCBasic. The secret code is randomly created and the analyzing of the player's input is done using mid().
There is no need to list the entire program as I have isolated the problem to one specific command.
The first For...Next loop is what the program requires. Starting from the beginning of the string, using mid() to determine which character is to be printed, then complete the loop with the last character. The variable 'i' will control which character to select. eg: if i = 1 then print the first character, "R", all the way to the 6th character, "P"
Ideally, that is what is supposed to happen, ideally... I have tried the first loop in several other Basic's and it runs fine. i = 1 character = "R" etc
Stumbled upon the solution. The second For...Next loop. Mid() is assuming that the first character of the string is represented by '0' zero.
Maybe it's just me or is there a minor problem? Just curious...
ps: Similar: rand(x), according to documentation, produces an integer from 0 to x, but it actually produces an integer number from 0 to x-1
Back story. Simple conversion of Mastermind from one Basic to RCBasic. The secret code is randomly created and the analyzing of the player's input is done using mid().
There is no need to list the entire program as I have isolated the problem to one specific command.
xmax = 800
ymax = 600
title$ = "MID() Test"
WindowOpen(1,title$,0,0,xmax,ymax,0)
CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
ClearCanvas
a$ = "RBGYOP"
for i = 1 to 6
print str(i) + " " + mid(a$, i, 1)
next
print " "
print "---------"
print " "
for i = 0 to 5
print str(i) + " " + mid(a$, i, 1)
next
update()
waitkey
The first For...Next loop is what the program requires. Starting from the beginning of the string, using mid() to determine which character is to be printed, then complete the loop with the last character. The variable 'i' will control which character to select. eg: if i = 1 then print the first character, "R", all the way to the 6th character, "P"
Ideally, that is what is supposed to happen, ideally... I have tried the first loop in several other Basic's and it runs fine. i = 1 character = "R" etc
Stumbled upon the solution. The second For...Next loop. Mid() is assuming that the first character of the string is represented by '0' zero.
Maybe it's just me or is there a minor problem? Just curious...
ps: Similar: rand(x), according to documentation, produces an integer from 0 to x, but it actually produces an integer number from 0 to x-1