Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello all, I'm currently trying to create a text based adventure in Visual Basic 6.
Although when I am comparing my IF statements to see which turn it is, it runs fine, but it also reads an IF statement that I don't want it to. Let me show you the code,
+++++++++++++++++++++++++++++++++++++++++++++
Private Sub go_Click()
' Room 3
If turn = 2 Then
If inp.Text = "go north" Then
desc.Caption = "A rusty sign reads 'Block E-7'. You are in a huge blank room with pale white walls. You glance over at the corner, there sits an overflowing bin"
loct.Caption = "Block E-7"
turn = 3
End If
Else
cant.Caption = "Cannot " + inp.Text
End IfIf turn = 2 Then
If inp.Text = "open door" Then
cant.Caption = "Door is locked."
turn = 2
End If
End If' Room 2
If turn = 1 Then
If inp.Text = "go north" Then
desc.Caption = "You are in a narrow corridor, the light continues north. You notice a small door to the right of you."
loct.Caption = "Narrow Corridor"
cant.Caption = ""
turn = 2
End If
Else
cant.Caption = "Cannot " + inp.Text
End Ifinp.Text = ""
End Sub
++++++++++++++++++++++++++++++++++++++++++++
When I am at Room 3, it correctly does it but it also does the code at Room 2:
If inp.Text = "go north" Then
When it is under If turn = 1.
Basically I want it to stop reading the If statements under it, or make sure that ONLY IF turn = 1 do that block, none other.I'm sorry if i sound confusing. Any questions please ask.
Thank you in advance.

You should use AND to tell your program not to execute a block of code unless both conditions are true.
+++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub go_Click()
' Room 3
If turn = 2 And inp.Text = "go north" Then
desc.Caption = "A rusty sign reads 'Block E-7'. You are in a huge blank room with pale white walls. You glance over at the corner, there sits an overflowing bin"
loct.Caption = "Block E-7"
cant.Caption = ""
turn = 3
Else
cant.Caption = "Cannot " + inp.Text
End IfIf turn = 2 And inp.Text = "open door" Then
cant.Caption = "Door is locked."
turn = 2
End If' Room 2
If turn = 1 And inp.Text = "go north" Then
desc.Caption = "You are in a narrow corridor, the light continues north. You notice a small door to the right of you."
loct.Caption = "Narrow Corridor"
cant.Caption = ""
turn = 2
Else
cant.Caption = "Cannot " + inp.Text
End Ifinp.Text = ""
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++++
This may be able to be optimised further, but I just corrected what was obvious to me at a glance.
Please let us know if you found someone's advice to be helpful.

Thanks, but now that I look further, I think the problem is that the variable in the IF block ISNT setting...

![]() |
Java Tic Tac Toe
|
help on creating DOS Batc...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |