Author |
Message |
Mabelma95
Joined: Thu Mar 05, 2009 10:49 am Posts: 31
|
Hi guys so I'm trying to do a test on math.random and I need the fla to change the score to one when the last sword thing is pressed, but it's not working and I really don'w know why. I'm posting the code and all of that. I really need help. If you need to contact me here's my email: [email protected] in advance.
_________________Click the pod to go to my website.
|
Sun May 03, 2009 2:13 pm |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
I have no idea what on earth you're trying to do. Could you try being more clear?
If you need to set the sorce to one, just say, on(release){score = 1;}
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Sun May 03, 2009 3:35 pm |
|
|
Mabelma95
Joined: Thu Mar 05, 2009 10:49 am Posts: 31
|
I need a number for 1 to 3 randomly. I tryed using math.random but it didn't work.Is the attachement working? If not tell me I'll give you a link to it. If you need anything else just ask.
_________________Click the pod to go to my website.
|
Sun May 03, 2009 4:15 pm |
|
|
x2i
Joined: Mon Aug 11, 2008 1:09 pm Posts: 166 Location: England lol
Gender: Male
Currently Playing: Minecraft
|
myNum = random(3)+1; should work, its not the best method but it'll do. Cue Evilagrams algorithm for Math.random() method...
|
Sun May 03, 2009 4:31 pm |
|
|
Mabelma95
Joined: Thu Mar 05, 2009 10:49 am Posts: 31
|
Thanks but I have a question why to I need to write +1? I only need 3 numbers. It still doesn't work.
_________________Click the pod to go to my website.
|
Sun May 03, 2009 6:28 pm |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
Ow. That's not how Math.Random works at all.
If you want a number equal to exactly 1, 2, or 3, then the correct method would be:
Score = Math.round(Math.random()*3+1);
If you want it to add to the current score, do this:
Score = Score + Math.round(Math.random()*3+1);
To explain the Math.random method a bit, it randomly generates an irrational number from 0 to 1. Just multiply by the range which you want (1-3 has a range of three) and add to the lowest number of the range (1 in this case). Math.round rounds the number to the neared value.
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Sun May 03, 2009 9:47 pm |
|
|
x2i
Joined: Mon Aug 11, 2008 1:09 pm Posts: 166 Location: England lol
Gender: Male
Currently Playing: Minecraft
|
Agreed that your Math.random() method works better but I think you'll find that writing random(5); for example will in fact generate a random number between 0 and 4, then add one will make it between 1 and 5. Try it.
|
Mon May 04, 2009 11:34 am |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
No it doesn't. It just generates a number between 1 and 0. Have you tried your own code?
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Mon May 04, 2009 11:37 am |
|
|
x2i
Joined: Mon Aug 11, 2008 1:09 pm Posts: 166 Location: England lol
Gender: Male
Currently Playing: Minecraft
|
Okay copy and paste this into the movies first frame and run it multiple times: Now tell me it doesn't generate a random number from 1 to 5 - I use it all the time when I don't want to get too complicated with the random numbers so I know it works!
|
Mon May 04, 2009 11:48 am |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
Wow, that's exactly the code I wrote. I put it on two frames, so it would loop and run every frame. Then I tested the movie. Here's the output: The code used was as follows Funny. It's not working as advertised. Here's the documentation on the random method: http://www.adobe.com/support/flash/acti ... ry466.htmlThere are no parameters for the random method. If you think I screwed up, here's the fla: http://dl.getdropbox.com/u/416986/temp/RandomTest.fla
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Mon May 04, 2009 11:56 am |
|
|
x2i
Joined: Mon Aug 11, 2008 1:09 pm Posts: 166 Location: England lol
Gender: Male
Currently Playing: Minecraft
|
Sorry but you are obviously misreading what I write, I wrote this Not this random() and Math.random are two different things.
|
Mon May 04, 2009 11:58 am |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
Weeeeeeeelllllll, f***. You quoted code from flash 4. http://www.adobe.com/support/flash/acti ... ry630.html It's a faulty implementation. Perhaps it generates less random numbers or lags more, f*** if I know. One thing for certain is that it can only generate integers, not irrational numbers, meaning that it's useless for a number of applications.
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Mon May 04, 2009 12:17 pm |
|
|
x2i
Joined: Mon Aug 11, 2008 1:09 pm Posts: 166 Location: England lol
Gender: Male
Currently Playing: Minecraft
|
Which is why I agreed with you that the Math.random method is far more efficient, but from experience with using flash for random number generating it works better for random numbers that are hidden behind the scenes - for example I use it to make events happen randomly like so: Works well enough for me and for a majority of users here learning flash it would probably work just as well too, but I guess teaching them the modern techniques will be better for them in the long run rather than using deprecated code all the time.
|
Mon May 04, 2009 12:26 pm |
|
|
Evilagram
Joined: Wed Apr 29, 2009 11:28 pm Posts: 323 Location: Nowhere, Antarctica
Gender: Anime Girl
Skype: Evilagram
|
I just do, EDIT: Ought to say more than that. Because it has a wider range and crap, it's more random, or something along those lines.
_________________Style [Stayl] (n) - One's unique and personal method of defacing a perfectly good piece of paper. READ THIS: http://ipgd.freehostia.com/copypasta.html
|
Mon May 04, 2009 12:50 pm |
|
|
Huntragon
Joined: Mon Aug 11, 2008 11:33 am Posts: 22
|
Try this code.I think is best than x21 and evilgram,but is a bit more complicated.
|
Tue May 05, 2009 12:36 am |
|
|