Hi. There is a difference between calling a part of a program that is labeled SUB and END SUB and between calling GOSUB and RETURN. A significant difference is also that variables that are not globally shared have no value or the same as in the part of the program between SUB and END SUB, if variable the same name in not declared as SHARED or is not used as parameter in SUB .
Sub example:
GoSub example:
Your code: (here is player name not returned to program, because variable name$ is not used as parameter for SUB or is not declared as shared)
so here is your program, because NAME is reserved statement in QB, so is here used PlayerName as SUB parameter and this is returned to program:
or next option how do it without parameter in SUB:
Just for the rest of the program: Options as it is written cannot work, because the parameter at the SUB input is called directions, but then in the sub it refers to the variable X, which, because it is not globally shared, will always 0 and the directions variable is not used in sub.
Sub example:
Code: (Select All)
'SUB use
Dim Shared PName As String 'try delete me and run it again!
NameIn
Print "Name:"; PName$
Sub NameIn
Input "input name:"; PName$
End Sub
GoSub example:
Code: (Select All)
'GoSUB use
GoSub NameIn
Print "Name:"; PName$
End
NameIn:
Input "input name:"; PName$
Return
Your code: (here is player name not returned to program, because variable name$ is not used as parameter for SUB or is not declared as shared)
Code: (Select All)
Dim money As Integer
Dim strength As Integer
Dim speed As Integer
Dim babes As Integer
Dim balls As Integer
Dim cash As Integer
Dim directions As Integer
'intro
Screen 0
Color 4, 0
Locate 8, 38
Print "The World"
Locate 8, 38
Print "Is Loading"
_Delay 5
'opening
Cls
Print "You finally got released from Prison at Kulai Headquarters"
Print "you looked at the sky and the people below it, you began"
Print "wondering, that you can become rich and powerfull"
Print "so you began your journey."
_Delay 10
'GoSub 10
MainPart
Sub MainPart
Cls
Print "Whats your name?"
Input name$
Sleep 2
Cls
Print "You are outside of Kulai Headquarters,"
Print "Where will you go?"
Print "(NORTH)"
Print "(SOUTH)"
End Sub
Sub Options (directions)
If x = north Then
Print "You Found A Market of Stores"
ElseIf x = south Then
Print "You went to Kulai Headquarters"
End If
End Sub
so here is your program, because NAME is reserved statement in QB, so is here used PlayerName as SUB parameter and this is returned to program:
Code: (Select All)
Dim money As Integer
Dim strength As Integer
Dim speed As Integer
Dim babes As Integer
Dim balls As Integer
Dim cash As Integer
Dim directions As Integer
'intro
Screen 0
Color 4, 0
Locate 8, 38
Print "The World"
Locate 8, 38
Print "Is Loading"
_Delay 5
'opening
Cls
Print "You finally got released from Prison at Kulai Headquarters"
Print "you looked at the sky and the people below it, you began"
Print "wondering, that you can become rich and powerfull"
Print "so you began your journey."
_Delay 10
'GoSub 10
MainPart name$
Print "Player name is:"; name$
Sub MainPart (PlayerName As String)
Cls
Print "Whats your name?"
Input PlayerName$
Sleep 2
Cls
Print "You are outside of Kulai Headquarters,"
Print "Where will you go?"
Print "(NORTH)"
Print "(SOUTH)"
End Sub
Sub Options (directions)
If x = north Then
Print "You Found A Market of Stores"
ElseIf x = south Then
Print "You went to Kulai Headquarters"
End If
End Sub
or next option how do it without parameter in SUB:
Code: (Select All)
Dim money As Integer
Dim strength As Integer
Dim speed As Integer
Dim babes As Integer
Dim balls As Integer
Dim cash As Integer
Dim directions As Integer
Dim Shared PlayerName As String
'intro
Screen 0
Color 4, 0
Locate 8, 38
Print "The World"
Locate 8, 38
Print "Is Loading"
_Delay 5
'opening
Cls
Print "You finally got released from Prison at Kulai Headquarters"
Print "you looked at the sky and the people below it, you began"
Print "wondering, that you can become rich and powerfull"
Print "so you began your journey."
_Delay 10
'GoSub 10
MainPart
Print "Player name is:"; PlayerName$
Sub MainPart
Cls
Print "Whats your name?"
Input PlayerName$
Sleep 2
Cls
Print "You are outside of Kulai Headquarters,"
Print "Where will you go?"
Print "(NORTH)"
Print "(SOUTH)"
End Sub
Sub Options (directions)
If x = north Then
Print "You Found A Market of Stores"
ElseIf x = south Then
Print "You went to Kulai Headquarters"
End If
End Sub
Just for the rest of the program: Options as it is written cannot work, because the parameter at the SUB input is called directions, but then in the sub it refers to the variable X, which, because it is not globally shared, will always 0 and the directions variable is not used in sub.