Hi; sorry if this has been covered elsewhere, but how do you program dice in Tads3?
In my current project, I’m trying to implement a D20 which, of course, when rolled would generate a number 1-20 which would then become a value to be applied to a number of things depending on context.
Currently, I have a do-nothing die:
class Die : Thing
vocabWords = 'die*dice'
dobjFor(Roll)
{
verify(){}
check(){}
action()
{
"{you/he} roll{s} a <<rand(20)>>. ";
}
}
;
The problems with this are
a) I want to exclude zero as a possible outcome, which it currently is. Preferably, I’d like to have it randomly select numbers between a given min and max, but so far the literature doesn’t seem to say how to do that.
Also,
b) It’s currently display only. What should I do so that I get a random value for computing purposes? Anonymous function? Script? Something else altogether?
Does anyone have any ideas?
ETA: Just updating to say that I worked out an awkward kludge for problem A,
class Die : Thing
vocabWords = 'die*dice'
dobjFor(Roll)
{
verify(){}
check(){}
action()
{
"{you/he} roll{s} a <<rand(gDobj.sides)>>. ";
}
}
;
d20: Die 'd20' 'D20'
"It's a blue, nearly round die with sides numbered one through twenty. "
sides = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
;
But I keep thinking there has got to be a more effecient way to do these things. Is there?
Also, still working on B.