dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Random numbers.

  1. #1
    Junior Member
    Join Date
    Jun 2005
    Posts
    9

    Random numbers.

    Hi!

    I am making a game in 3DFA.
    And I want to work with a dice.
    Everything is good and all but I don't exactly know the script for a random number.
    I found the functions of Blanius.
    This script:
    Code:
    function randomRange(Min,Max){
        return random(Max-Min+1)+Min;
    }
    And how can I get the output into a textbox. What should I insert as the variable?


    Can someone help?
    Thnx!

    Grtz,, Yoer88
    Last edited by Yoer88; 08-06-2005 at 11:09 AM.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    put that function in your starting script.

    Then when you want to get a new random number you call the function like this

    die1=root.randomRange(1,6)

    die1 will now equal a number between 1 and 6 if you have an editbox with the variable die1 it will show you the number

    http://bretlanius.com/flash/die.html
    Attached Files Attached Files

  3. #3
    Junior Member
    Join Date
    Jun 2005
    Posts
    9
    Thnx allot!

    Another question about it
    My game is becoming a version of a well known game. (don't know how they call it in English).
    But what I want is when; die1==1 the position of the player (just a circle with gradient) must go forward one position. And when die1==2 it has to go forward 2 positions etc.

    So my questions: How can I set the positions (?? position1=element("player").x.y=145.200 ??).
    And how can I make sure he counts the value of die1 to the previous values.

    I hope it is clear what I mean and I hope you can help me.
    Grtz,, Yoer88
    Last edited by Yoer88; 08-07-2005 at 02:59 AM.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    it depends alot on how you are displaying them, and how you are tracking where they are. I'm guessing that you may need to rethink that part of your game. This is something you needed to plan for when starting the project.

    you set the position of an object with myobject.position.x and I think myobject.x works just as well. And substitute y for the x for the other dimension.

    You should read up on ARRAYS as I've found that is usually the best way to do this sort of board game thing.

  5. #5
    Junior Member
    Join Date
    Jun 2005
    Posts
    9
    I see. Alright I rethink it then.
    But can you tell me anyway how to make something so the value of die1 is added to a total?

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    just add it.... total+=die

  7. #7
    Junior Member
    Join Date
    Jun 2005
    Posts
    9
    oOw
    could of thought of that myself of course..

  8. #8
    Game Master ConnELITE's Avatar
    Join Date
    Apr 2005
    Location
    United States, DC
    Posts
    473
    this is easy you just need to add in some editboxes or something, like in your starting script say

    die=whatever the die says (create some scriot within die to make this work)
    position=0 (position will be the varible)
    position1=number.x and number.y
    position2=number.x and number.y
    (ect for hom many positions you have)

    then say
    if [thedierolls]{
    position+=die
    }

    if position=1{
    element (player)=position1
    }



    thered be a lot of scripting but this is what i first thought of, it has soem holes but you could fill em in.
    BC

  9. #9
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Something I Remember Seeing

    Hi,

    With regards to random numbers, you'll notice that in the 3DFA viewer, the numbers aren't very random. If you restart the movie, the numbers are the same the second time around.

    However, it seems it's OK in the exported movie, so maybe it's not a problem.

    Morgan
    Please note that my domain has changed to http://www.morganmultinational.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center