Vb.net 不返回值的情况
我在我的文本冒险中设置了一个选择案例,当输入单词“inventory”和“pickupblade/takeblade”时,应该调用一个子例程。但是,尽管案例1和案例2正确调用了该子例程,但未调用该子例程。代码不会抛出任何异常,但不会调用相应的子例程Vb.net 不返回值的情况,vb.net,Vb.net,我在我的文本冒险中设置了一个选择案例,当输入单词“inventory”和“pickupblade/takeblade”时,应该调用一个子例程。但是,尽管案例1和案例2正确调用了该子例程,但未调用该子例程。代码不会抛出任何异常,但不会调用相应的子例程 while playing console.write("Where to next? ") ' get the command from user command = console.readline
while playing
console.write("Where to next? ")
' get the command from user
command = console.readline()
' command should be of either a single verb, single direction, or verb noun
' parse the command then use verb to identify appropriate action to take
commandWords = Split(command," ")
select case ubound(commandwords)
case 0
' 'verb' command
select case ucase(commandWords(0))
case "N","S","E","W","NORTH","SOUTH","EAST","WEST"
if tryMoving(commandWords(0)) then displayRoom
case "INVENTORY"
if trymoving(commandwords(0)) then inventory
case "PICKUPBLADE", "TAKEBLADE"
if trymoving(commandwords(0)) then pickup_blade
end select
case 1
' 'verb noun' commands
select case ucase(commandWords(0))
case "GO","MOVE"
if trymoving(commandwords(1)) then displayRoom
end select
end select
end while
End Sub
sub displayRoom()
console.title=room(location)
console.out.writeline(desc(location))
if objLocation(0) = location Then
Console.WriteLine("You can see a blade")
Console.WriteLine("You can pickup this item.")
end if
end sub
sub pickup_blade()
if objLocation(0) = location Then
Console.WriteLine("You have picked up the blade.")
objLocation(0) = 0
end if
end sub
sub inventory()
Console.WriteLine("------------------------------------------------------")
Console.WriteLine("----------------------Inventory-----------------------")
Console.WriteLine("------------------------------------------------------")
if objLocation(0) = 0 Then
Console.WriteLine("> Blade")
elseif objLocation(1) = 0 Then
Console.WriteLine("> Gloves")
else
Console.WriteLine("Inventory is empty.")
end if
end sub
此类型的命令不需要使用
trymoving()
。您可以使用case 3
选择case ubound(commandwords)和选择case ucase(commandwords(0))
,查找与“INVENTORY”匹配的内容。因此,您的输入命令中必须有3个空格…类似于“INVENTORY what the bleep”,而您可能希望它仅使用“INVENTORY”。@Idle\u注意,我已更改了代码,因此现在“INVENTORY”和“PICKUPBLADE”命令位于案例0下。但是,子例程仍然没有被调用?我已经更新了显示更改的代码段。你确定播放
是真的吗?@itsLex是的,播放
在程序开始时设置为真,并且“N”、“S”、“E”、“W”
命令所有工作尝试移动()做什么?在我看来,您不必成功地“尝试移动”以执行库存命令。该函数很可能返回false。