Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 10:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Loop in variable?
PostPosted: August 15th, 2010, 10:18 pm 
Offline

Joined: December 13th, 2008, 3:15 pm
Posts: 152
Location: Brasil
Opus: 7
OS: Windows 7 x64
System: Asus P5Q3 Deluxe, Core 2 Duo E8500, 8 Gb DDR3 1333 mhz, His IceQ5 5770 HD Graphic Card, Samsung T220 Monitor; Lenovo G550 T6600, 4 GB DDR3 - 15,6".
Well, I have already discussed the matter but have not found a way to do this through the forum, so here I am again ...

I need to adjust the final outcome of the script below in randomChap variable, for the same number is not repeated sequentially, because this is sometimes chosen two times in a row.

Follows the beautiful script, developed by the wise Osni:
Code:
i=0
while(i<chapNum){
   randomChap[i]=String.random(chapNum)+1
   var j=0
      while(j<i) {
         if(randomChap[j]==randomChap[i]) {
            randomChap[i]=String.random(chapNum)+1
            j=0
         } else {
            j++
         }
      }
   i++
}
c=0


I found an interesting example, but done in Flash Actionscript for loop of 10 numbers, where a given variable reads the result, avoiding the sequence repeats itself.
Code:
Set Variable: "i" = 1
Loop While (i <> 11)
Set Variable: "rnd" = Random (10)
Set Variable: "x" = 1
Loop While (x <> (Length(Temp)+1))
If ((Substring (Temp, x, 1)) eq rnd)
Set Variable: "rnd" = ""
End If
Set Variable: "x" = x+1
End Loop
If (rnd ne "")
Set Variable: "Temp" = Temp & rnd
Set Variable: "i" = i + 1
End If
End Loop


In the case of the opus script in question, I think might need to add a new variable to the script, to read the final result shown for the variable randomChap, preventing the first chosen number is show repeated, but how to do this?

So again I ask everyone's help to solve this problem. Thank you.


You do not have the required permissions to view the files attached to this post.

_________________
"To the ignorant, old age is the winter of life, for the wise, is the season of harvest."
It is not easy to translate the world into a binary code of 0s and 1s, but in scripts, anything is possible!


For this message NilsonBrasil has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Loop in variable?
PostPosted: August 16th, 2010, 10:25 am 
Offline

Joined: February 18th, 2005, 5:44 pm
Posts: 17
Location: Michigan (USA)
Opus: V7.04
OS: Win7 32-bit
System: Pentium QUAD 4GB RAM ATI HD 57XX
Not sure if this is what you want, but this will produce a random number between 1 and 10 and will never repeat the same number consecutively.
Code:
x_current = Math.round(Math.random()*9)+1;
for(var c=1; c<100; c++){
if(x_current==stored_x){
   x_current = Math.round(Math.random()*9)+1;
  }else{
    stored_x=x_current;
    break;
  }
}


x_current and stored_x are pub variables to maintain persistent values.

Fish


For this message FishBox has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Loop in variable?
PostPosted: August 16th, 2010, 5:26 pm 
Offline

Joined: December 13th, 2008, 3:15 pm
Posts: 152
Location: Brasil
Opus: 7
OS: Windows 7 x64
System: Asus P5Q3 Deluxe, Core 2 Duo E8500, 8 Gb DDR3 1333 mhz, His IceQ5 5770 HD Graphic Card, Samsung T220 Monitor; Lenovo G550 T6600, 4 GB DDR3 - 15,6".
FishBox, thank you for your attention.
My problem here is not having the random numbers between 01 and 10 but have a random order of randonChap repeating itself at the first available alternative. Open the file RandomChaps and click the button several times. You see that sometimes the first choice of the order will be displayed again. This is my problem - to avoid such repetition. I added your script, and the variables needed in the publication, but even so randomChap keeps repeating their values at the first available option.
So how to change the programming of Opus Script in this file to avoid this?

_________________
"To the ignorant, old age is the winter of life, for the wise, is the season of harvest."
It is not easy to translate the world into a binary code of 0s and 1s, but in scripts, anything is possible!


For this message NilsonBrasil has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Loop in variable?
PostPosted: August 17th, 2010, 1:08 am 
Offline

Joined: February 18th, 2005, 5:44 pm
Posts: 17
Location: Michigan (USA)
Opus: V7.04
OS: Win7 32-bit
System: Pentium QUAD 4GB RAM ATI HD 57XX
I've attached an updated pub that should accomplish what you want. In the pub, I just commented out your script and added mine to the button trigger.

For those who are curious, I pasted the relevant code below:

Code:
a_random_count = 4;//number of chapter numbers to display
a_array_stored_numbers[a_random_count];
//a_firstchapnumber_stored-this is a page var that is persistent. stores previous first number
a_number_of_chapters = 10;
for(c=0; c<100; c++){
  a_firstchapnumber_current = Math.round(Math.random()*(a_number_of_chapters-1))+1
  if(a_firstchapnumber_current != a_firstchapnumber_stored){
    //a unique number is found. Add it to stored numbers array
    //and break the loop
    a_firstchapnumber_stored = a_firstchapnumber_current;
    a_array_stored_numbers[0] = a_firstchapnumber_current;
    break;
  }
}
var _array_element_count = 1;//used to track which stored_numbers element to place rnd number in. 0 element already populated above
while(_array_element_count < a_random_count){
  var _number_check = Math.round(Math.random()*(a_number_of_chapters-1))+1;
  var _match_found = 0;
  for(arrelement=0; arrelement<a_random_count; arrelement++){
     if(a_array_stored_numbers[arrelement] == _number_check){
        _match_found = 1;
        break;
     }
  }
  if(_match_found == 0){
    a_array_stored_numbers[_array_element_count] = _number_check;
    _array_element_count++;
  }
 
}


Fish


You do not have the required permissions to view the files attached to this post.


For this message FishBox has been thanked by : mackavi, NilsonBrasil


Top
 Profile  
 
 Post subject: Loop in variable?
PostPosted: August 17th, 2010, 3:03 am 
Offline

Joined: December 13th, 2008, 3:15 pm
Posts: 152
Location: Brasil
Opus: 7
OS: Windows 7 x64
System: Asus P5Q3 Deluxe, Core 2 Duo E8500, 8 Gb DDR3 1333 mhz, His IceQ5 5770 HD Graphic Card, Samsung T220 Monitor; Lenovo G550 T6600, 4 GB DDR3 - 15,6".
Thanks, FishBox!
This will save me the embarrassment of seeing RandomChap repeating the same number in sequence.
Helped me a lot your willingness to post the file imp with the entire script functional! I am very happy!

My best regards!!!

_________________
"To the ignorant, old age is the winter of life, for the wise, is the season of harvest."
It is not easy to translate the world into a binary code of 0s and 1s, but in scripts, anything is possible!


For this message NilsonBrasil has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Loop in variable with band of chapters...
PostPosted: February 5th, 2011, 11:02 pm 
Offline

Joined: December 13th, 2008, 3:15 pm
Posts: 152
Location: Brasil
Opus: 7
OS: Windows 7 x64
System: Asus P5Q3 Deluxe, Core 2 Duo E8500, 8 Gb DDR3 1333 mhz, His IceQ5 5770 HD Graphic Card, Samsung T220 Monitor; Lenovo G550 T6600, 4 GB DDR3 - 15,6".
Hello Opus Lovers...,

Thanks to help from everyone, I'm almost finished my intent, but a question still seems disturbing ...

I wonder how to modify the script in this topic, used by me in a publication with 10 chapters. How can I make the script work on a specific range, say 07 to 10 of chapter, ignoring the June 1? As it stands, random chapters 10-10 may be the result ...

Code:

i=0
while(i<chapNum){
   randomChap[i]=String.random(chapNum)+1
   var j=0
      while(j<i) {
         if(randomChap[j]==randomChap[i]) {
            randomChap[i]=String.random(chapNum)+1
            j=0
         } else {
            j++
         }
      }
   i++
}
c=0

a_random_count = 4;//number of chapter numbers to display
a_array_stored_numbers[a_random_count];
//a_firstchapnumber_stored-this is a page var that is persistent. stores previous first number
a_number_of_chapters = 10;
for(c=0; c<100; c++){
  a_firstchapnumber_current = Math.round(Math.random()*(a_number_of_chapters-1))+1
  if(a_firstchapnumber_current != a_firstchapnumber_stored){
    //a unique number is found. Add it to stored numbers array
    //and break the loop
    a_firstchapnumber_stored = a_firstchapnumber_current;
    a_array_stored_numbers[0] = a_firstchapnumber_current;
    break;
  }
}
var _array_element_count = 1;//used to track which stored_numbers element to place rnd number in. 0 element already populated above
while(_array_element_count < a_random_count){
  var _number_check = Math.round(Math.random()*(a_number_of_chapters-1))+1;
  var _match_found = 0;
  for(arrelement=0; arrelement<a_random_count; arrelement++){
     if(a_array_stored_numbers[arrelement] == _number_check){
        _match_found = 1;
        break;
     }
  }
  if(_match_found == 0){
    a_array_stored_numbers[_array_element_count] = _number_check;
    _array_element_count++;
  }
 
}



I tried in every way, but did not get any satisfactory result. The main idea here is to publish two tracks working with sequential ... 1 to 6 from 7 to 10 ... I can even change the variable value chapnum to 6 ... preventing them from entering the four remaining chapters randomization of chapters .. but how to ignore the June 1, randomizing the remaining chapters ... 7, 8, 9 and 10 ... that is the question ..

I look a great view of the valiant fellow ...

_________________
"To the ignorant, old age is the winter of life, for the wise, is the season of harvest."
It is not easy to translate the world into a binary code of 0s and 1s, but in scripts, anything is possible!


For this message NilsonBrasil has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group