Jump to content

Easy question: My script will cycle 1 -> 2 -> 3... to six - I need '1' to come after '6'


Recommended Posts

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 post
Share on other sites
  • Moderators

CoffeeJoe,

Use the Mod operator on the variable within the cycle - although the result will run from 0-5 rather then 1-6.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

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

 

Musashi-C64.png

"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 post
Share on other sites
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 post
Share on other sites
  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
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 by CoffeeJoe
Link to post
Share on other sites
  • Moderators

CoffeJoe,

Glad I could help.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
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

 

Musashi-C64.png

"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 post
Share on other sites

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 by CoffeeJoe
Link to post
Share on other sites
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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...