Zylice Posted August 25, 2015 Share Posted August 25, 2015 (edited) 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 August 25, 2015 by Zylice Link to comment Share on other sites More sharing options...
simtam Posted August 25, 2015 Share Posted August 25, 2015 What happens if you change "Int Hungry = Utility.RandomInt(0,5)" to "Int Hungry = 2" ? Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted August 25, 2015 Share Posted August 25, 2015 (edited) 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 EndFunctionThe 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 August 25, 2015 by sLoPpYdOtBiGhOlE Link to comment Share on other sites More sharing options...
Zylice Posted August 26, 2015 Author Share Posted August 26, 2015 (edited) 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 EndFunctionThe 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 EndFunctionOkay. Thanks for pointing that out! I will give it a try. :smile: EDIT: It works, thank you! *^_^* Edited August 26, 2015 by Zylice Link to comment Share on other sites More sharing options...
Recommended Posts