A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 43

Thread: Betting randomizer trotting

  1. #1
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    Betting randomizer trotting

    Hi all,

    I'm toying around with something for my dad, he used to pick up an dice to
    get a horse to bet on in the past and I want to make an application that will randomize the result of the horserace slightly influenced by 4 things. I attach the complete movie.

    If you look at it or just read here (you wont understand the swedish in the movie) I list:
    Häst 1 *editbox1* *editbox2* and *pushbutton* for max 15 horses
    Häst 2
    Häst 3
    and so on

    At the press on "Klar Klicka här"-button the application should show the winner, 2nd placed and 3rd placed horse. And it should be an randomized result slightly influenced by the 4 values from *editbox1* *editbox2* *pushbutton* and Wildnessfactor - the values are in percentage 0-99 in all cases but the pushbutton. Editbox1 is expertsranking, editbox2 is myownranking and pushbutton is an top3finisherdeclaration but I don't want it to be an simple addition that creates the winner of the race...

    My question is not really about how to get an randomized result but I ask you what kind of equation should I use ...? Can randomize be slightly influenced, like random a number between 1-15 and favor number 1, 6 and 7 80% over the other numbers?

    E. g. if häst1 editbox1 is 99 and editbox2 is 99 and the pushbutton is on then it means the experts thinks this horse wins99% and I think it wins99% and I declare a top3finish for it BUT still I want it to be an randomizething ... And how can I implement the Wildnesspercentage - maybe it should be the variable that throws everything upsidedown. This is early in the developing stage, I remember how I programmed the C64 to randomize numbers a long time ago in basic (10 var = x
    20 for x = 1 to 100
    30 random x
    40 print x
    50 goto 10
    something and run one could not see the numbers they were spitted out soo fast and one needed to push break to stop it and see the numbers)... I will do more specified questions later perhaps, this is fundamental question!
    Last edited by SirN; 08-15-2007 at 04:50 PM.

  2. #2
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Quote Originally Posted by SirN
    My question is not really about how to get an randomized result but I ask you what kind of equation should I use ...? Can randomize be slightly influenced, like random a number between 1-15 and favor number 1, 6 and 7 80% over the other numbers?
    One quick way is fill an array containing 1-15 numbers with desired favor,.. something like this:

    a = new Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5); // number 5 is 5 times more likely to be picked in random than number 1..
    b = Math.random()*a.length;
    c = a[b]; // here we get number between 1-5 from array

  3. #3
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    that will suit me perfectly, thanks

  4. #4
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    I'm going bananas, help me please, is it bugs or am I doing something wrong. There used to be an tick for element has properties before and if ticked one could .show or .hide the elements from an script- now it just don't work in v4.9.6.2 .

    Let me explain from start:
    http://web.comhem.se/~u53935741/kjellstravslumpare.html is the exported one and it doesn't work at all like the internally run one. zip is attached to this post...

    The movie starts with scene1 and displays a couple of elements and 4 buttons, the movie is stopped. And after pressing the button V/P the scene2 should play (and it does internally but not exported) and display a couple of other elements (an text, an editbox and an click button)...

    The editbox should be initialized with the text 0 but it is not - First problem!

    When enterring 1 in the editbox and pressing the clickbutton "Klar" an script on the clickbutton should make a couple of other elements show but it doesn't - Second problem!

    It used to be an slection for all elements "element has properties" and without that checked one could not show or hide the element from an script, that does not exist anymore or is moved- where/how, is it what I miss?
    Last edited by SirN; 08-15-2007 at 04:50 PM.

  5. #5
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Quote Originally Posted by SirN
    The movie starts with scene1 and displays a couple of elements and 4 buttons, the movie is stopped. And after pressing the button V/P the scene2 should play (and it does internally but not exported) and display a couple of other elements (an text, an editbox and an click button)...
    I used "Goto frame" (Goto and play) action instead of the script and it worked fine...
    I'm not sure what is wrong with script,.. mayby it needs 'root.' or 'movie name.' before "Scene 2 VP" or something.

    I got this error when exporting but I did not find where it came as you have lot of elements there

    "Syntax error on line 66 if platstick1 = on
    'else' without matching 'if' on line 71 else"


    You might want to check your "if" syntax.. comparison operator is '==' in javascript.. this should work better:

    if (platstick1 == on) {
    Placetarif();
    phase1var = rankvar1 + placevar / 2;
    }

    So check out script syntax (help file helps ) and try using fixed 'actions' in place of scripts if possible, just to get thing rolling at first.

  6. #6
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    Quote Originally Posted by Finjogi
    I used "Goto frame" (Goto and play) action instead of the script and it worked fine...
    Ok I'll try that!


    Quote Originally Posted by Finjogi
    I'm not sure what is wrong with script,.. mayby it needs 'root.' or 'movie name.' before "Scene 2 VP" or something.
    Hmm, ...

    Quote Originally Posted by Finjogi
    I got this error when exporting but I did not find where it came as you have lot of elements there

    "Syntax error on line 66 if platstick1 = on
    'else' without matching 'if' on line 71 else"


    and try using fixed 'actions' in place of scripts if possible, just to get thing rolling at first.
    The syntax error is unrelated, I know why it appears and it's not bothering me, I test my movie and it works if run internally, but not exported and it must be a bug, if i change to GoTo frame I can get the exported to work perhaps, but the script on the button is an problem that I care about the most. Maybe I should mail about bugs to 3DFA... To use actions instead of script might be possible, I will test some...

  7. #7
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    script "root.gotoAndPlay ("Scene 2 VP");" seems to work with V/PButton when exported..

  8. #8
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    (EDIT it is off course the AntalHTextButton I talk about and it's script - it is the only button displaying after choosing V/P)
    In the script at the AntalHTextButton I have tried all kind of variants e.g.:
    if (antalh == 1)
    { element xxxxxyyyyy.show;
    }
    this used to work but I also tried all below

    also

    if (antalh = 1)
    if (antalh == "1")
    if (antalh = "1")
    if (antalh == '1')
    if (antalh = '1') after pressing the button it changes to 49 in the editbox LOL!
    if antalh == 1
    if antalh = 1
    Last edited by SirN; 08-01-2007 at 10:32 AM.

  9. #9
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Latest version of 3dfa handles many thing way differently than earlier version...
    .show seems to be obsolete feature as help file shows at the bottom, but this one works..
    element ("H1TextButton").visible=true;

    and trace helps you to track if code goes where you want it to go.. like:

    if (antalh == "1")
    {
    trace("antalh==1");
    ...

  10. #10
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    Quote Originally Posted by Finjogi
    One quick way is fill an array containing 1-15 numbers with desired favor,.. something like this:

    a = new Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5); // number 5 is 5 times more likely to be picked in random than number 1..
    b = Math.random()*a.length;
    c = a[b]; // here we get number between 1-5 from array
    Ok, now I'm ready to tackle this completely new thing for me - array! I wonder:
    If an calculation results in that horse 1 should have 99 spots in the array and another calculation results in that horse 2 should have 80 spots in the array, how can I fill the spots in the array?
    99spots of horse1 to array = x?x
    80spots of horse2 to array = x??x
    a = new Array(x?x, x??x)

    Can it be that simple?

  11. #11
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Quote Originally Posted by SirN
    how can I fill the spots in the array?
    99spots of horse1 to array = x?x
    80spots of horse2 to array = x??x
    a = new Array(x?x, x??x)

    Can it be that simple?
    No, you should fill it in somekind of loop
    a = new Array();
    for(i=0;i<99;i++){
    a.push(1); // odds for horse 1, 99 slots for number 1
    }
    for(i=0;i<80;i++){
    a.push(2); // odds for horse 2, 80 slots for number 2
    }
    So array would be filled with 99 number 1's and 80 number 2's.

    But if you have lot of horses with 70-99 odds this array thing goes bit long for the job as you have to fill the array quite a lot.

    Mayby this one could work better (easier..)

    horse_odds = new Array(99, 80, 70, 87, 40); // odds for each horse, 99 for horse1, 80 for horse2 etc
    random_max = 99+80+70+87+40;
    r = Math.random()*random_max;
    n=0;
    for(i=0; i<horse_odds.length; i++){
    n = n + horse_odds[i]; // horse1 0-98, horse2 99-178, horse3 179-248 etc..
    if(r<n) {
    // horse number i gets random hit
    trace(i);
    break; // get out of loop
    }

    }

    Hard to explain but anyway

  12. #12
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    I do understand your first example, and I'm greatly helped by it, I thank you for helping me with the important
    >for(i=0;i<99;i++){
    >a.push(1); // odds for horse 1, 99 slots for number 1
    >}
    part - it will suit me to start with ( but as you mention, it will be a lot in the array in the end)

    The other example I do need to study deeply to understand completely, but I could allready see that it is more effective ...

  13. #13
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    Plays ok internally - malfunctions exported!

    I'm puzzled by the fact that the movie plays ok internally, but when exported it malfunctions!

    If anybody wants to look at this, here's the instructions (3DFA v4.9.6.5)(also tested in v4.9.4):
    1. Enter 5 and 5 at the editboxes next to Häst 1
    2. Enter 4 and 2 at the editboxes next to Häst 2
    (if you do that internally then you must press backspace to erase an invisble zero first - exported the zeros show up)
    3. Press the button Beräkna/Slumpa

    The array slumpklump is filled. The variable vinnareblir is the pick from the array (the winner) and should be displayed in the editbox at the top-right (and is displayed when played internally). As you press the button the randomize happens again and the result can vary (either 1 or 2 should be displayed as winner.

    Online exported malfunction at: http://web.comhem.se/~u53935741/travexperten4965.html

    I attach an .zip with source here.

    I think the cacheing in my explorer is bugging me sometimes, when I make a change and export/upload sometimes I don't think my browser loads the newly uploaded... Does anyone know how to clear the cache of Internet Explorer 7, pressing the refresh button does not load the new?
    Last edited by SirN; 09-25-2007 at 01:49 AM.

  14. #14
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    I have tried several ways to make the movie work exported:
    1. "Stop when finished" and played at the button
    2. "Restart when finished" and stopped in sceneaction and played at button
    3 and 4. Adding a second scene stopping the first scene and displaying the winnereditbox in the second scene/at the press of the button.

    all works played internally, but malfunctions when exported (if not the IE cache is bugging it)

  15. #15
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    .continued
    5. I've declared vinnareblir as an integer variable in starting script
    6. I've started the editboxes with number 1 instead of zero because perhaps
    the zero is understood as NULL

    The fact remains both in version 4.6.4 and 4.9.6.5 that the movie works great internally but malfunctions when exported. When pressing beräkna the variable vinnareblir turns into "undefined"...

    I am going to mail this as an bug to 3DFA!

  16. #16
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    I did some debugging... in that "Beräkna" button script I added few debug lines (adjusted that editbox to multiline one.. good way to output debugging stuff)

    longness = "a:" + slumpklump.length;
    mellansteg = Math.random()*slumpklump.length;
    longness += "\n b:" + mellansteg;
    vinnareblir = slumpklump[mellansteg];
    longness += "\n c:" + vinnareblir;

    in 3dfa:
    a:8
    b:0.0095234524
    c:1

    in flash:
    a:8
    b:1.22679114714265
    c:undefined

    So it seems that 3dfa helps you and converts "mellansteg" float value to integer and that is used to get value from "slumpklump" array.
    Flash is more strict and wont accept or convert float "mellansteg" as index of the array.
    It is simple to fix, convert float value to integer value in that line:
    mellansteg = Math.floor(Math.random()*slumpklump.length);

  17. #17
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    (this was written before I read the above post)

    I have gotten instant reply about the bugreport, good!

    The thing that comes to mind is the old school of programming (basic on C64), there it was very important to first declare the existance of an integer variable then fill the variable with an integer number and later on make use of the variable content. In 3DFA that buisness is completely gone, you can have an empty startscript and then at the pushbutton-script just introduce that an vinnareblir = calculationcalculation and immediatly make use of it in further ways at other scripts and elements.

    It makes me think that I should not display the editbox which shows the variable vinnareblir because the calculation of that variable is not done until the button is pressed. Soo, I just create another scene and stop the movie until buttonpress (and variable content is done) then in scene 2 I display the editbox which makes use of the variable...
    Last edited by SirN; 08-16-2007 at 02:53 AM.

  18. #18
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    Quote Originally Posted by Finjogi
    I did some debugging...

    Flash is more strict and wont accept or convert float "mellansteg" as index of the array.
    It is simple to fix, convert float value to integer value in that line:
    mellansteg = Math.floor(Math.random()*slumpklump.length);
    Problem cured, now both internal and exported works. Fantastic! I could not have made it w/o your help, thanks again!

    Now, if there's anything I can do for forumqueries, I have a slight feeling that if I try to help someone I just create a mess (since I am so novice at most issues), I better be quiet until I really have good knowledge of the subject...

    All I can do now is to promise that I will create an English language version when done, both source and exported for all to use (if U think that random thing belongs in horse racing/trotting betting - some would argue not)!

  19. #19
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    I picked up this after a break

    After hitting a wall of errors and malfunctions I quit the project, but now I've picked it up again. I just found out how to use the scriptcommand trace and I think I can make prgress with the use of it, though I've been told to use it before I've not understood how and why, now I do, sorry for my stupidity about it!

    I seem to have problems with functionscript - passing numbers back and forth from one place to another and I might get back to ask about it later in more detail if need be, I will try my best at it myself first and make use of my book Flash MX actionscript bible (soon Actionscript 3 bible)...

    It would be cool to get this done completed because it should not be too hard to be done and I bet some of you guys can have it done in short time, it keeps me busy for hours...

    I will share the movie if finished and along the way

  20. #20
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    (I'm using 3DFA v4.9.6.8 latest version that is)

    Is the array method removeAll (only avail in 3dfa not in AS accourding to help file) really not availible in 3dfa any more?

    I make my case clearer and complete the problem description here below:
    I'm creating an betting program, that will pick the winner and runner up and third place finisher of horse race. After entering values E and K for participating horses (leaving it at 0 for non-participating ones) and ticking or not ticking the placefinisherTextButton and Array is filled up with various amounts of horse numbers at the push of the KlarTextButton and at the end of the script a random pick is made to pick the winner from the array -

    longness = slumpklump.length;
    mellansteg = Math.floor(Math.random()*slumpklump.length);
    vinnareblir = slumpklump[mellansteg]; // vinnareblir = winnerbecomes

    Now to pick the runner up I would like to erase the number picked as the winner (e.g. 1) and display runnerupbecomes/tvaablir but it doesn't go easy for me, no matter how I try I cant erase from the array -
    removeAll (1) // still keeps the number 1 in the array

    The .movie is downloadable at http://web.comhem.se/~u53935741/kjellBoy4968v092.zip and exported at http://web.comhem.se/~u53935741/kjellboy4968v092.html (as you see in the exported it sometimes picks the same horse to finish 1st and second...)

    (simplifying instructions -
    1. enter in editbox häst 1 E 2 and K 2 and häst 2 E 2 and K 2 only
    2. then press the button at bottom right and see the result in the editboxes in the top right and middle right, the editbox that shows up below the pushbutton displays the array content 1,1,2,2 and the 1's should have been erased from there)

    If you look at the spot to fix at in the movie go to the KlarTextButton buttondownscript bottom and see the problem area where I want to erase content of array and repick from array...
    Last edited by SirN; 09-25-2007 at 02:40 AM.

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