CoffeeJoe Posted September 10, 2021 Share Posted September 10, 2021 Wasn't sure where to ask this - I'm not stuck and nothing is broke so its not a support question. looking for suggestions on how best to do this... I have a plan with a few if statements and at least one global flag variable but it feels ... inelegant The script will cycle through 6 different images as it runs (more than 6 cycles) and when it runs again it should pick up where it left off. This isn't a new idea so I'm sure others have developed some simple ways to do this. Id like to hear what they are. Please Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2021 Moderators Share Posted September 10, 2021 CoffeeJoe, Use the Mod operator on the variable within the cycle - although the result will run from 0-5 rather then 1-6. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Musashi Posted September 10, 2021 Share Posted September 10, 2021 Try : HotKeySet("{ESC}", "_Terminate") Global $iImageNo, $iCounter = 0 While True $iImageNo = Mod($iCounter, 6) + 1 ConsoleWrite("Imgage No : " & $iImageNo & @CRLF) Sleep(500) $iCounter += 1 WEnd Func _Terminate() Exit EndFunc ;==>_Terminate "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
CoffeeJoe Posted September 10, 2021 Author Share Posted September 10, 2021 7 minutes ago, Melba23 said: CoffeeJoe, Use the Mod operator on the variable within the cycle - although the result will run from 0-5 rather then 1-6. M23 M23, So wrap it in Int( ) and reset it when it equals 1? If Mod($count, 6) = 1 Then $count = 1 ? I must be missing something about Mod because that would be the same as if $count = 7 Then $count = 1 This was at the core of my initial strategy... It gets more complex as I'm updating and moving images that are not in the "count" position Script will move 1, 2, 3 & 4 to new positions, set a new image in 5 and reset the image that's in 6 ( guictrlsetimage "" ) Then move 2, 3, 4 & 5 to new positions, set a new image in 6 and reset 1... perpetually (maybe) I am trying to prevent my tenancy to write spaghetti code with patches wherever needed to get the job done... Some of my old code gives me a headache trying to remember why that ... even works - looks like it shouldn't ... 🙈 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2021 Moderators Share Posted September 10, 2021 CoffeeJoe, Mod works like this: HotKeySet("{ESC}", "_Exit") ; The count variable $iCount = 0 While 1 ; Current value ConsoleWrite($iCount & @CRLF) ; Get the Mod of the current value + 1 $iCount = Mod($iCount + 1, 6) ; Just to keep it slow enough to read Sleep(500) WEnd Func _Exit() Exit EndFunc Is that clearer? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CoffeeJoe Posted September 10, 2021 Author Share Posted September 10, 2021 (edited) 7 minutes ago, Melba23 said: CoffeeJoe, Mod works like this: HotKeySet("{ESC}", "_Exit") ; The count variable $iCount = 0 While 1 ; Current value ConsoleWrite($iCount & @CRLF) ; Get the Mod of the current value + 1 $iCount = Mod($iCount + 1, 6) ; Just to keep it slow enough to read Sleep(500) WEnd Func _Exit() Exit EndFunc Is that clearer? M23 Very - I was thinking about it wrong - thx that qualifies as far more elegant! Edited September 10, 2021 by CoffeeJoe Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2021 Moderators Share Posted September 10, 2021 CoffeJoe, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JockoDundee Posted September 11, 2021 Share Posted September 11, 2021 Also, HotKeySet("{ESC}", "_Exit") While 1 For $iCount = 0 To 5 ; Current value ConsoleWrite($iCount & @CRLF) ; Just to keep it slow enough to read Sleep(500) Next WEnd Func _Exit() Exit EndFunc Maybe less floating point arithmetic. Musashi 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Musashi Posted September 11, 2021 Share Posted September 11, 2021 22 minutes ago, JockoDundee said: Maybe less floating point arithmetic. You are right, of course. I was just not sure, if @CoffeeJoe needs the continuous main counter somewhere else. But that would also work without modulo. HotKeySet("{ESC}", "_Exit") Local $iMainCounter = 0 While 1 For $iCount = 0 To 5 $iMainCounter += 1 ; Current value ConsoleWrite("Picture No.: " & $iCount+1 & " MainCounter: " & $iMainCounter & @CRLF) ; Just to keep it slow enough to read Sleep(500) Next WEnd Func _Exit() Exit EndFunc ;==>_Exit "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
CoffeeJoe Posted September 13, 2021 Author Share Posted September 13, 2021 (edited) Just a follow up I wrote what I envisioned - it was slower than I as expecting I tweaked it to get the speed reasonable and then I had terrible flicker I read much of what M23 has said about flicker... I'm updating the image before it is even displayed on the screen (rendered off-screen) The images move into the viewable area and move down as they should All images are disabled and none of them overlap any other controls... Still lots of flicker... I reverted to my prior iteration where the pic controls are stationary and the image is set to them in succession... This is considerably faster and there is no flicker... Only complaint is that the images appear 1.. 2 .. 3 so it looks kinda like its scrolling but it too choppy to be convincing. Its a work in progress and I may rework it again and give the moving images another go and try to isolate and solve the flicker... Not up for it at the moment. Thanks to everyone who chimed in I'm learning more everyday. I have a new challenge (part of this project - just with the previous method) but I want to tackle it a bit before asking for help. Edited September 13, 2021 by CoffeeJoe Link to comment Share on other sites More sharing options...
CoffeeJoe Posted September 13, 2021 Author Share Posted September 13, 2021 On 9/11/2021 at 3:45 PM, Musashi said: You are right, of course. I was just not sure, if @CoffeeJoe needs the continuous main counter somewhere else. But that would also work without modulo. HotKeySet("{ESC}", "_Exit") Local $iMainCounter = 0 While 1 For $iCount = 0 To 5 $iMainCounter += 1 ; Current value ConsoleWrite("Picture No.: " & $iCount+1 & " MainCounter: " & $iMainCounter & @CRLF) ; Just to keep it slow enough to read Sleep(500) Next WEnd Func _Exit() Exit EndFunc ;==>_Exit Mod worked exactly as advertised and its irrelevant if the actual count is 693,000,000 so long as the script knows which image is in which position (which it does) Thanks 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