VB.Net编码错误

时间:2017-01-12 18:10:23

标签: vb.net visual-studio

因此,作为我大学工作的一部分,我一直致力于一个带有功能性战斗系统的游戏和游戏启动程序。这是在Visual Studio中完成的,但是,我有一个问题。

每当你准备参加战斗时,我都会收到这个错误: http://prntscr.com/duswke

以下是导致错误的代码:

    Console.WriteLine("You have arrived at the " & Place(randomNum) & " aboard your ship")
    System.Threading.Thread.Sleep(1000)
    Console.WriteLine("You look around to check for hostiles...")
    System.Threading.Thread.Sleep(5000)

    Enemy(1) = "An enemy runs towards you and  engages with you in combat!"
    Enemy(2) = "You see nothing around you but stars, It's all clear"

    Randomize()
    randomNum2 = Int(Int((2 * Rnd()) + 1))

    Console.WriteLine("" & Enemy(randomNum2) & "")

    If Enemy(1) Then
        System.Threading.Thread.Sleep(5000)
        Console.Clear()
        Call Sub() Combat()
    ElseIf Enemy(2) Then
        Console.Clear()
        Console.WriteLine("You have found some treasure deep within the " & Place(randomNum) & " ")
        System.Threading.Thread.Sleep(2000)
        Console.WriteLine("Continue Adventuring?")

  Console.Clear()
        Call Sub() Combat()
    End If

基本上应该发生的是它应该清除控制台并打开战斗菜单(Console.WriteLine()         Console.WriteLine(“1 - Attack”)         Console.WriteLine()         Console.WriteLine(“2 - 库存”)         Console.WriteLine()         Console.WriteLine(“3 - Run”)         Console.WriteLine()) 一旦打开,使用chrMenu字符,您应该能够选择并执行和选项,但它会停在“If Enemy(1)它不应该。任何帮助都表示赞赏。

1 个答案:

答案 0 :(得分:2)

你不能这样做:

If Enemy(1) Then

因为位置1的项目是:

Enemy(1) = "An enemy runs towards you and  engages with you in combat!"

这是一个字符串。 if语句中的条件必须生成TrueFalse值。

所以也许你想检查一下这个值是否相等然后再做一些事情。像这样:

If Enemy(1) = "Something you want to compare it to" Then
    ' Do Something here
End If