dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: a long code how can i make it shortly

  1. #1
    Member
    Join Date
    May 2016
    Posts
    98

    a long code how can i make it shortly

    hi
    i have a long code how can i make it shortly
    kofa.text = 1 to 11
    kofa2.text = 1 to 11
    PHP Code:
    onFrame (1) {  
        if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){ 
              var 
    i:intMath.randomRange(1,10)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(1,10)
               var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
     if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(10,20)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(10,20)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }  
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(20,30)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(20,30)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(30,40)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(30,40)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(40,50)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(40,50)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(50,60)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(50,60)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(60,70)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(60,70)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(70,80)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(70,80)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(80,90)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(80,90)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==10 and _parent.kofa2.text==10 and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(90,100)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(90,100)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }  
    if( 
    _parent.kofa.text==11 and _parent.kofa2.text==11 and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(100,1000)
              var 
    n:intMath.randomRange(100,1000)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
               var 
    i:intMath.randomRange(100,1000)
              var 
    n:intMath.randomRange(100,1000)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(10,20)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(10,20)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }
    }                                                   
    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==10 and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==11 and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
          var 
    i:intMath.randomRange(100,1000)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(100,1000)
              var 
    n:intMath.randomRange(1,10)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(20,30)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(30,40)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(40,50)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(50,60)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(60,70)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(70,80)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(80,90)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==10 and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(90,100)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }

    if( 
    _parent.kofa.text==11 and _parent.kofa2.text==and _parent.kofakind.text==and _parent.kofakind2.text==1){
              var 
    i:intMath.randomRange(100,100)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;               
       while(
    i<or i==or n==0){
              var 
    i:intMath.randomRange(100,100)
              var 
    n:intMath.randomRange(10,20)
                
    n1.text=i;
                
    n2.text=n;           
    }


  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    The simplest way to do this would be to get rid of the duplicates.
    I've noticed that you have _parent.kofakind.text==1 and _parent.kofakind2.text==1 in all the if statements. So the best thing to do for that would be to combine that into one if statement that covers all of them at once. I mean, if either of those aren't 1 then you don't need to check the rest.

    That's not directly related but just a suggestion. A simple way to deal with what you want would be to combine everything into an array. Like this:
    Code:
    var kArray:Array=[[1,10],[10,20],[20,30],[30,40],[40,50],[50,60],[60,70],[70,80],[80,90],[90,100],[100,1000]];
    Then all you need is something like this:
    Code:
    var i:int= Math.randomRange(kArray[int(_parent.kofa.text)-1][0],kArray[int(_parent.kofa.text)-1][1]);
    var n:int= Math.randomRange(kArray[int(_parent.kofa2.text)-1][0],kArray[int(_parent.kofa2.text)-1][1]);
    This will follow the patter you've set up.

    Also, this is bad:
    Code:
    var i:int= Math.randomRange(20,30);
    var n:int= Math.randomRange(20,30);
    n1.text=i;
    n2.text=n;
    while(i<n or i==n or n==0){
      var i:int= Math.randomRange(20,30);
      var n:int= Math.randomRange(20,30);
      n1.text=i;
      n2.text=n;
    }
    You're reinitializing both the i and the n variable in the loop. This would be a memory leak. Plus you're doing this with a variable in the loop conditions. Not sure exactly what you're trying there but you should either use a different variable or just get rid of the "var n:int=" aspect of it. Just "n=" would work if you want to keep using that var.
    .

  3. #3
    Member
    Join Date
    May 2016
    Posts
    98
    you are a good man swak

    can you solve this problem

    Attached Files Attached Files

  4. #4
    Member
    Join Date
    May 2016
    Posts
    98
    how can i make random division in Previous file

    what is the code for random division

    i want the result number must be integer

    it means number1 accepted division number2

    any help for this code ??

    please
    Last edited by kofa; 12-28-2017 at 02:17 AM.

  5. #5
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    Code:
    while(int(n1.text)<=int(n2.text)){
    n1.text= String(int(n1.text)+1);
    }
    I might have gotten the syntax slightly wrong for this but give it a go.
    Code:
    int(100/Math.random()*20)
    This will end up with the number 100 divided by a number between 0-20. Changing a number to an integer is simple. Just do int(number).
    .

  6. #6
    Member
    Join Date
    May 2016
    Posts
    98
    sorry swak
    not working

  7. #7
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    This should do almost everything. There was one problem with it. k1 is == 1 then k2 will be as well. Not sure if that's fine but it wouldn't take much more to fix.
    Code:
    onSelfEvent (Load) {
        var kArray:Array=[[1,10],[10,20],[20,30],[30,40],[40,50],[50,60],[60,70],[70,80],[80,90],[90,100],[100,1000]];
        var k1:int = int(int(_parent.kofa.text)-1);
        var k2:int = int(int(_parent.kofa2.text)-1);
        k2=(k1>=k2)?k2:k1;
        var i:int;
        var n:int;
    }
    //onSelfEvent(EnterFrame){
    //}
    onFrame (1) {
        i= int(Math.randomRange(kArray[k1][0],kArray[k1][1]));
        if(k1==k2){
            n= int(Math.randomRange(kArray[k2][0],i));
        } else {
            n= int(Math.randomRange(kArray[k2][0],kArray[k2][1]));
        }
        n1.text=i;
        n2.text=n;
        reslut.text=  n1.text-n2.text;
    }
    If you want I can explain what the purpose of the Events are. This will explain why I separated the code into different events. Also, what onSelfEvent(EnterFrame) is.
    .

  8. #8
    Member
    Join Date
    May 2016
    Posts
    98
    yes now it working fine
    thanks swak
    can you make random division in this code

  9. #9
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,769
    What exactly do you mean by random division?
    .

  10. #10
    Member
    Join Date
    May 2016
    Posts
    98
    in Previous code
    how to make
    reslut.text= n1.text / n2.text;
    i want the result number must be integer
    it means number1 accepted division number2 in random mode
    for example if n1=10 , the n2 must be 5 or 2
    if n1 = 20 , the n2 must be 5 or 2 or 4 or 10
    Last edited by kofa; 01-03-2018 at 03:25 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