jebus495 Posted January 28, 2009 Share Posted January 28, 2009 I tried searching but found nothing about this. The goal here is for the user of my program (this is not the full script) to be able to set how often this function happens. I understand what I have done here might be a bit of a roundabout way of accomplishing this so any alternatives would be good. It seems odd to me that $gotofish never = 1 even when "fishsometimes is set to 1. Perhaps I have made a silly mistake? CODEFunc gotofish() $dontfishafterlvl = 0 $fishsometimes = IniRead("NAMEOFINI.ini", "Values", "fishsometimes", "NONE SET") $gotofish = Random (1, $fishsometimes) If $gotofish = 1 Then MouseMove(260, 350) Sleep(1000) MouseClick("Left") Sleep(1000) MouseMove(200, 375) Sleep(1000) MouseClick("left") Sleep(1000) fish() Else gotoarena() EndIf EndFunc ;==>gotofish Link to comment Share on other sites More sharing options...
Skruge Posted January 28, 2009 Share Posted January 28, 2009 It's not explicitly stated in the documentation, but Min must be less than Max. If they're equal, as in your case, Random returns 0 and sets @error to 1. I don't know if this is what you're trying to accomplish, but I think this is what you want based on the name of your variable...$gotofish = Random (0, $fishsometimes, 1) If $fishsometimes = 0, the result will always be 0. (Because the inputs are invalid, not because the range is 0-0) If $fishsometimes = 1, the result can be 0 or 1. (Range: 0-1) Note: Setting the third parameter (Flag) to 1 ensures that you don't get a fraction between 0 and 1. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2009 Moderators Share Posted January 28, 2009 jebus495, Ran into the same problem a while ago. In the end I decided that I had to code around it:; Get a random number If $aIndex_Array[0] = 1 Then ; If only 1 entry, Random will return 0 so force 1 $iRandom_Choice = 1 Else ; Get a random integer within the index bounds $iRandom_Choice = Random(1, $aIndex_Array[0], 1) EndIf There was an attempt to change this behaviour, but the Devs said "No" in no uncertain terms! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Spiff59 Posted January 28, 2009 Share Posted January 28, 2009 Of course he could avoid triggering an @error condition with this variation: $gotofish = $fishsometimes * Random (0, 1, 1) Link to comment Share on other sites More sharing options...
jebus495 Posted January 28, 2009 Author Share Posted January 28, 2009 Thanks for all the responses. I went with $gotofish = Random (1, $fishsometimes,1) Basically just because the way I have my config set up. 1 = on 0 = off. Now 0 = off 1 = on 2 = half on 3 = 1/4 on 4 = 1/8 on and so on Almost everything in the program I have written needs to be at least a little random or I'll get "caught" Link to comment Share on other sites More sharing options...
Spiff59 Posted January 29, 2009 Share Posted January 29, 2009 (edited) If you need the 0 through 4 codes, this does what you want in a single line: While 1 $fishingfrequency = InputBox("","Input fishingfrequency (0-4, enter to exit): "); 0=Never, 1=25%, 2=50%, 3=75%, 4=Always If $fishingfrequency = "" then ExitLoop $j = 0 For $i = 1 to 1000 $gotofish = ($fishingfrequency * .25) > Random() If $gotofish Then $j += 1; Went fishing EndIf Next MsgBox(1,"","With fishingfrequency set to " & $fishingfrequency & ", you'll go fishing " & $j & " times out of 1000" ) WEnd Or, if you don't really require the 0-4 stuff, just set your variable to whatever percent you desire: While 1 $fishingfrequency = InputBox("","Input fishingfrequency (0-100%, enter to exit): ") If $fishingfrequency = "" then ExitLoop $j = 0 For $i = 1 to 1000 $gotofish = ($fishingfrequency / 100) > Random() If $gotofish Then $j += 1; Went fishing EndIf Next MsgBox(1,"","With fishingfrequency set to " & $fishingfrequency & ", you'll go fishing " & $j & " times out of 1000" ) WEnd Edited January 29, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now