stevetroughton Posted October 14, 2023 Share Posted October 14, 2023 I'm trying to end a loop script with a timer. I've developed a little game for the children and their friends, something and nothing but they love it. However I'm struggling to end a loop script step to make the game work properly. Upon Clicking the 'Go' button, the below script runs. First it generates a random number that will be used as the seconds for the timer. The timer begins, then the script keeps looping through the records, pausing for 2 seconds (the records just being a name and a funny picture of each child). Once the seconds have ran out, this could be 8 seconds, 5 seconds, 10 seconds etc depending upon what random number is generated, whichever record it stops at, or should I say whichever child it stops at, that child does a funny forfeit. I just don't know the script step for a timer, and for it to run using the random generated number as the seconds . This is what I have. The TIMER SCRIPT STEP & Exit Loop If are where I am struggling. Set Variable [$RecordCount; Value: Get(TotalRecordCount)] Set Field [Game::Random Number Global; Int (Random*20)+3] Set Variable [$RandomNumber; Value: Game::Random Number Global] .......TIMER SCRIPT STEP TO GO HERE I THINK AND NOT SURE HOW TO WRITE IT Loop Exit Loop If ........[ONCE THE TIME REACHES $RandomNumber] SOMETHING LIKE THIS I THINK If [Get(ActiveRecordNumber) = $RecordCount] Go to Record/Request/Page [First] Else Go to Record/Request/Page [Next; Exit after last:Off] Pause/Resume Script [Duration (seconds): 2] Ends If End Loop Link to comment Share on other sites More sharing options...
comment Posted October 14, 2023 Share Posted October 14, 2023 (edited) If I understand the rules correctly, you want to show a sequence of records in a loop, pausing at each record for 2 seconds, until the total time has run out? In such case, you could simply select a random number of records to show, instead of a random number of seconds. Then have your loop subtract 1 from this number until it reaches 0, for example: # SHOW 2 - 11 RECORDS Set Variable [ $n; Int ( Random * 10 ) + 2 ] Loop Exit Loop If [ $n ≤ 0 ] If [ Get(RecordNumber) = Get (FoundCount) ] Go to Record/Request/Page [ First ] Else Go to Record/Request/Page [ Next ] End If Pause/Resume Script [ Duration (seconds): 2 ] Set Variable [ $n; $n - 1 ] End Loop A more interesting variation could be to select a random record in each step, instead of repeating the same sequence. Edited October 14, 2023 by comment Link to comment Share on other sites More sharing options...
stevetroughton Posted October 14, 2023 Author Share Posted October 14, 2023 Hi, Yes your understanding of the rules is correct. Your alternative suggestion..... what if I only have 5 records, the anticipation of who it will land on won't last long. The fun for them is waiting for it to stop, and on who, so it may loop through each child several times. Cheers Link to comment Share on other sites More sharing options...
Solution comment Posted October 14, 2023 Solution Share Posted October 14, 2023 8 minutes ago, stevetroughton said: what if I only have 5 records, the anticipation of who it will land on won't last long. I think you misunderstood me. I meant select a random record in each step. The number of steps could be random (as it is now) or fixed. Have a look at the demo I posted here: https://fmforums.com/topic/108790-graphical-random-number-generator/?do=findComment&comment=488423 Link to comment Share on other sites More sharing options...
stevetroughton Posted October 14, 2023 Author Share Posted October 14, 2023 Oh yes, that is quite brilliant, thank you. It's amazing, the simplest of games that keeps them occupied. It's s bit like presents when they discard the toy and choose to play with the box LOL. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now