emmanuel Posted June 1, 2004 Share Posted June 1, 2004 so, I just whipped up this little die roller UDF, I'd like to have it put the rolls into an array, with each roll being a seperate entry in the array (then just add the contents of the array to display total), but have no clue as to how to do that... ; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x / NT ; Author: Emmanuel Pleshe <emmanuel.pleshe@pse.com> ; ; Script Function: ; Die roller function. ; Rolls $d (die) $x times, returns $total ; ; ---------------------------------------------------------------------------- ; ---------------------------------------------------------------------------- ; Script Start ; ---------------------------------------------------------------------------- ; example use ;#cs $D4TOTAL = 0; define var $D6TOTAL = 0; define var MsgBox(0, "test", "5d4 test: " & _dieroller(4, 5, $D4TOTAL)) MsgBox(0, "test", "3d6 test: " & _dieroller(6, 3, $D6TOTAL)) #ce ; $D is the die to roll, $X is the number of times to roll it, $total is the value to return to. Func _dieroller($D, $X, $TOTAL) Do $ROLL = Int(Random($D) + 1) $TOTAL = $ROLL + $TOTAL $REPS = $REPS + 1 Until $REPS = $X Return $TOTAL EndFunc ;==>_dieroller "I'm not even supposed to be here today!" -Dante (Hicks) Link to comment Share on other sites More sharing options...
Valik Posted June 1, 2004 Share Posted June 1, 2004 You could put them in a delimited string, then after you finish rolling, StringSplit that, add them up, replace $array[0] with the total of all the rolls, then the rest of array is filled with each individual roll. Link to comment Share on other sites More sharing options...
emmanuel Posted June 1, 2004 Author Share Posted June 1, 2004 that's exactly what I thought of after I posted! glad that I'm on the same line of thought that you are... however, check my last post in v3 support, I must be doing something wrong, I don't see any values in the array... (nor can I think of how to add all the contents of the array...) "I'm not even supposed to be here today!" -Dante (Hicks) Link to comment Share on other sites More sharing options...
CyberSlug Posted June 1, 2004 Share Posted June 1, 2004 $array = StringSplit("31415", "");sample array ; Array sum ; Note: normally we should start $i at index 0, but an array generated ; with StringSplit uses element 0 for special purposes $sum = 0 For $i = 1 to UBound($array)-1 $sum = $sum + $array[$i] Next Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! 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