Pontus Posted May 16, 2003 Posted May 16, 2003 How "translateble" is the following C++ code into a script? Is it possible to make a script that functions this way at all? int Ob(int n) { int temp; if (n == 0) { return(0); } else { temp = rand() % 6 + 1; if (temp == 6) { temp = Ob(2); } return (temp + Ob(n - 1)); } } Many thanks in advance!
Lee Smith Posted May 16, 2003 Posted May 16, 2003 Why not just explain what it is you are trying to accomplish?
Pontus Posted May 16, 2003 Author Posted May 16, 2003 Ehum OK. Well it's about dice rolls. So-called unlimited dice rolls. When you roll a 6, you roll that dice together with a new one again until you don't have anymore 6:s left. The 'Ob' is the sign for 'Obest
CobaltSky Posted May 16, 2003 Posted May 16, 2003 Hello Pontus, I think that the Swedish>>English translation in your original posting is more confounding than the C++>>FileMaker translation. However I suspect that what you are looking for may be along the lines of: SetField{"gCounter", "0"] Loop If ["not gCounter = 0"] SetField{"gDiceRoll", "Int(Random * 6) + 1"] End If Exit Loop If ["not gDiceRoll = 6"] End Loop SetField{"RepeatRollCount", "gCounter - 1"] You gave us a rather cryptic explanation of what you want to do (admittedly it was less cryptic than your original post), but you didn't say anything about *why* you want to do it or what you hope to achieve by it. If what I've suggested is wide of the mark, then perhaps it will nonetheless give you some ideas to work with.
Pontus Posted May 16, 2003 Author Posted May 16, 2003 Why? Hmm. Oh yes it was a character generator for a
Lee Smith Posted May 16, 2003 Posted May 16, 2003 Hi Pontus, Take a look at this site: http://www.fmfiles.com/enduserhom3.html Among other things there, it has a couple of dice games. HTH Lee
Pontus Posted May 19, 2003 Author Posted May 19, 2003 Thanks for the link, Lee. And thanks for your script too CobaltSky, with the following changes I've managed to get it workin': Loop If ["not gCounter = 0"] Set Field ["gDiceRoll","Int(Random*6)+1"] End if If ["not gDiceRoll = 6"] Set Field ["gDiceCount","gDiceCount + gDiceRoll"] Set Field ["gCounter","gCounter - 1"] End if Exit loop If ["gCounter=0"] If ["gDiceRoll = 6"] Set Field ["gCounter","gCounter + 1"] End if End Loop Before using it one must set gCounter to the number of dices one want to roll, and gDiceCount to zero. Then let the dice roll and take the sum from gDiceCount. Thanks for the help, everyone!
Recommended Posts
This topic is 7863 days old. Please don't post here. Open a new topic instead.
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