Coding help,

johnny56

New Member
Joined
Jun 1, 2018
Messages
1
Hey guys, coding a basic ai for a game, and the enemy always moves down and left, instead of what I tell it to do.
Thanks!
Code:
Sub moveStart()
'2 right, 3 down, left to 10
   If turn = 0 Then
   Range("monster.l1").Value = Range("monster.l1").Value + 1
   turn = 1
    MsgBox turn    
   GoTo Ender
ElseIf turn = 1 Then
    turn = 2
    MsgBox turn
ElseIf turn = 2 Then    
    Range("monster.t1").Value = Range("monster.t1").Value + 3
    turn = 3
    MsgBox turn
    GoTo EnderElseIf turn = 3 Then
    If Range("monster.l1").Value > 10 Then
        Range("monster.l1").Value = Range("monster.l1").Value - 1        
       MsgBox turn
        GoTo Ender
    ElseIf Range("monster.l1").Value = 10 Then
        turn = 4
        MsgBox turn
    End If
ElseIf turn = 4 Then
    turn = 0
End If
Ender: End Sub
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
Sub moveStart()
'2 right, 3 down, left to 10
select case turn
  case 0 
    Range("monster.l1").Value = Range("monster.l1").Value + 1
    turn = 1
    MsgBox turn    
   goTo Ender

  case 1 
    turn = 2
    MsgBox turn
    goTo Ender  

  case 2 
     Range("monster.t1").Value = Range("monster.t1").Value + 3
     turn = 3
     MsgBox turn
    goTo Ender
  
  case 4 
     turn = 0
End select

Ender: 
End Sub

'i dont know where you want this to run...

If Range("monster.l1").Value > 10 Then
Range("monster.l1").Value = Range("monster.l1").Value - 1
MsgBox turn
goTo Ender
Else Range("monster.l1").Value = 10 Then
turn = 4
MsgBox turn
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top