Jump to content

Help With Random Integer Script


Zylice

Recommended Posts

I've been trying to make an animal follower that does random things whenever you activate it (Similar to Darkfox127's 'The Chicken Returns') by using random integers. However; only the first action works. None of the other actions ever work for some reason even if I swap them, it's always the first one. Perhaps you could tell me what I'm doing wrong. Thanks.

 

 


 
Actor Property Alice Auto 
GlobalVariable Property AliceFollowing Auto 
ObjectReference Property AliceLoc Auto
ObjectReference Property RanLoc01 Auto
ObjectReference Property RanLoc02 Auto
ObjectReference Property RanLoc03 Auto
 
Event OnActivate(ObjectReference akActionRef)
Interact()
 
EndEvent
 
 
Function Interact() 
 
Int Hungry = Utility.RandomInt(0,5)
 
 
If Hungry == 0
  debug.messagebox("Alice is thirsty.")
If (AliceFollowing.GetValue()) == 1 ; If Alice is following 
  Alice.OpenInventory()
ElseIf Hungry == 1
  debug.messagebox("Alice is hungry.")
If (AliceFollowing.GetValue()) == 1 ; If Alice is following 
  Alice.OpenInventory()
ElseIf Hungry == 2
  debug.messagebox("Alice likes your outfit.")
ElseIf Hungry == 3
  debug.messagebox("Alice wants to play!")
ElseIf Hungry == 4
  debug.messagebox("Alice wants to go on an adventure.")
 
 
 
 
EndIf
EndIf
EndIf
EndFunction

 

 

Edited by Zylice
Link to comment
Share on other sites

The problem is your If statements are not in order.

Try:

Function Interact()    
    Int Hungry = Utility.RandomInt(0,4)
    If Hungry == 0
        debug.messagebox("Alice is thirsty.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
            Alice.OpenInventory()
        EndIf
    ElseIf Hungry == 1
        debug.messagebox("Alice is hungry.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
              Alice.OpenInventory()
        EndIf    
    ElseIf Hungry == 2
          debug.messagebox("Alice likes your outfit.")
    ElseIf Hungry == 3
          debug.messagebox("Alice wants to play!")
    ElseIf Hungry == 4
          debug.messagebox("Alice wants to go on an adventure.")
    EndIf
EndFunction

The way you had it meant that it could never fire anything unless Hungry was 0.

this is what you have (using indents so you can see where If/ElseIf/EndIf starts and ends)

Function Interact()
    Int Hungry = Utility.RandomInt(0,5)
    If Hungry == 0
        debug.messagebox("Alice is thirsty.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
              Alice.OpenInventory()
        ElseIf Hungry == 1
            debug.messagebox("Alice is hungry.")
            If (AliceFollowing.GetValue()) == 1 ; If Alice is following
                  Alice.OpenInventory()
            ElseIf Hungry == 2
                  debug.messagebox("Alice likes your outfit.")
            ElseIf Hungry == 3
                  debug.messagebox("Alice wants to play!")
            ElseIf Hungry == 4
                  debug.messagebox("Alice wants to go on an adventure.")
            EndIf
        EndIf
    EndIf
EndFunction
Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

 

The problem is your If statements are not in order.

Try:

Function Interact()    
    Int Hungry = Utility.RandomInt(0,4)
    If Hungry == 0
        debug.messagebox("Alice is thirsty.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
            Alice.OpenInventory()
        EndIf
    ElseIf Hungry == 1
        debug.messagebox("Alice is hungry.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
              Alice.OpenInventory()
        EndIf    
    ElseIf Hungry == 2
          debug.messagebox("Alice likes your outfit.")
    ElseIf Hungry == 3
          debug.messagebox("Alice wants to play!")
    ElseIf Hungry == 4
          debug.messagebox("Alice wants to go on an adventure.")
    EndIf
EndFunction

The way you had it meant that it could never fire anything unless Hungry was 0.

this is what you have (using indents so you can see where If/ElseIf/EndIf starts and ends)

Function Interact()
    Int Hungry = Utility.RandomInt(0,5)
    If Hungry == 0
        debug.messagebox("Alice is thirsty.")
        If (AliceFollowing.GetValue()) == 1 ; If Alice is following
              Alice.OpenInventory()
        ElseIf Hungry == 1
            debug.messagebox("Alice is hungry.")
            If (AliceFollowing.GetValue()) == 1 ; If Alice is following
                  Alice.OpenInventory()
            ElseIf Hungry == 2
                  debug.messagebox("Alice likes your outfit.")
            ElseIf Hungry == 3
                  debug.messagebox("Alice wants to play!")
            ElseIf Hungry == 4
                  debug.messagebox("Alice wants to go on an adventure.")
            EndIf
        EndIf
    EndIf
EndFunction

Okay. Thanks for pointing that out! I will give it a try. :smile:

 

EDIT: It works, thank you! *^_^*

Edited by Zylice
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...