-
Title? Am I King or something?
Dynamic dice?
Hey, I'm trying to make a dice-rolling program that can change the amount of sides available, for a small demo. It's for a game I am developing just to see if I can, so I'm in no rush. This is my entire (and very short) source code:
Code:
stop();
dieSides = sidesInput;
wepBonus = bonusInput;
btnRoll.onRelease = function(){
die = Math.round(Math.random() * sidesInput);
die += wepBonus;
} // end roll
As you can see, I have a dynamic text field named "sidesInput" and "bonusInput". I make the variable "dieSides" equal to the text field "sidesInput", as well with "wepBonus" and "bonusInput".
When I click the button "btnRoll", the text field "die" should become equal to a random number multiplied by "sidesInput" rounded to the nearest whole number, with the variable "wepBonus" added to the final result. In theory, this should work for me. But whenever I press "btnRoll" and start off the function that creates the output, all I get is an annoying "NaN" as the output.
How can I fix this?
Last edited by --Fusiox--; 11-13-2009 at 02:54 PM.
-
Pumpkin Carving 2008
Code:
stop();
dieSides = Number(sidesInput.text);
wepBonus = Number(bonusInput.text);
btnRoll.onRelease = function(){
die = Math.round(Math.random() * diceSides);
die += wepBonus;
} // end roll
Last edited by ImprisonedPride; 11-10-2009 at 08:27 PM.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Senior Member
I would suggest using Math.ceil instead of Math.round, as dice rolls start from 1, not 0.
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
Title? Am I King or something?
Oh, so it's a code thing, not a logical error, then...
Every time I post something here, I learn a bunch of new things =D
-
I created a random dice rolling program might as well show it since you are talking about it http://www.flashdice.com
real simple code used
onClipEvent (load) {
gotoAndStop(random(7)+2);
}
onClipEvent (load) {
this._rotation = random(90)+90;
}
code used to make it selecting a random frame in the movie it all worked out pretty good let me know what you think.
-
Title? Am I King or something?
@Cubolution,
Nice dice! (Pretty punny, huh) However, it still is a bit different from mine in the fact that it uses the numbers to go to frames and directions. That I know how to do. However, I'm not manipulating the numbers to go to frames; I'm manipulating the numbers themselves. I'm trying to make the dice have any amount of sides that the user puts in.
Which brings me to my second point...
My God, I'm a noob! Yeah, I've tried your method ImprisonedPride, but it still outputs NaN at the "die" field. I'm very annoyed at Flash right now.
Did you use AS2 or AS3 in your code edit? That is, is the var type Number and the prefix ".text" actually relevant in older code syntaxes? If you used AS3, that would explain it all.
I'm uploading a version of the .fla on the site. Get it here:
dynamicDice cs3.fla
Thanks for all your help!
-Fusiox
-
Senior Member
-_-
Your code won't work.
1) You are intialising your variables at the start, hence it tries to convert the "type number of..." to number and store that, rather than what the user entered.
2)die is the dynamic textbox's instance name, and you are using it as a variable for calculation and directly inside the textbox's var property as well.....it dosen't work that way. the instance name is just a reference.
http://www.mediafire.com/?ntwmmmzxvzn
Last edited by bluemagica; 11-13-2009 at 04:02 PM.
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|