Correct Menu Nav System

Find quick help here to get you started with Hollywood
dewindatws
Posts: 12
Joined: Wed Sep 06, 2023 8:54 pm
Location: Wales
Contact:

Correct Menu Nav System

Post by dewindatws »

Hello everyone,

I've been working on making a simple clone of the Perfect Dark Menu system, and the way I've wrote my menu system I think is quite clunky and would be better done as a seperate function with cases but I am struggling to wrap my head around it.

I know the IF statements are both ugly and impractical, would anyone be able to walk me through writing a better system please, I've included the code below..

Code: Select all

@DISPLAY {width = 320, height = 240, ScaleMode = #SCALEMODE_AUTO, ScaleWidth = #NATIVE, ScaleHeight = #NATIVE}
NUMBER = 3
menuvar = 2

OpenMusic(1,"pdtraining.mod")
LoadBrush(1,"pd.jpeg",{scalewidth = 320, scaleheight = 240})
LoadSample(1,"menu.iff")
BlurBrush(1,NUMBER)
BrushToBGPic(1,1)
PlayMusic(1)

Function p_render()
SetFont(#SANS, 12)
CreateBrush(10,160,20,$2F52C9,{AlphaTransparency = True})
CreateTextObject(1,"Small but Perfect Menu",{ALIGN = #LEFT,COLOUR = #WHITE})
CreateBrush(11,160,140,$0E204A,{AlphaTransparency = True})
SetFont(#MONOSPACE, 15)

If menuvar = 2
CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf

If menuvar = 3
CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf

If menuvar = 4
CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf

If menuvar = 5
CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf

If menuvar = 6
CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #RED})
Else
CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #WHITE})
EndIf
BeginRefresh()
Cls()
DisplayBGPic(1)
DisplayBrush(10,80,20,{transparency = "25%"})
DisplayTextObject(1,100,22)
DisplayBrush(11,80,40,{transparency = "50%"})
Global k = 0
For i = 2 To 6 Step 1
DisplayTextObject(i,120,48+k)
If i = 5
    k = k + 25
    Else
k = k + 25
EndIf
Next
EndRefresh()

EndFunction


Function p_logic()
    If kbUP = 1
        If menuvar = 2
            menuvar = 2
            Else
                PlaySample(1)
                menuvar = menuvar - 1
        EndIf
    EndIf

    If kbDOWN = 1
        If menuvar = 6
            menuvar = 6
            Else
                PlaySample(1)
                menuvar = menuvar + 1
        EndIf
    EndIf
EndFunction

Function p_mainloop()
    p_render()
    p_logic()
EndFunction


Function p_HandlerFunc(msg)
    ;SWITCH FOR HANDLER FUNC
    Switch(msg.action)
        Case "OnRawKeyDown":
            Switch UpperStr(msg.key)
            ;Movement Flags Down
                Case "UP":
                    kbUP = 1
                Case "DOWN":
                    kbDOWN = 1
                Case "ESC":
                    End()
            EndSwitch

        ;Movement Flags Up
        Case "OnRawKeyUp":
            Switch UpperStr(msg.key)
                Case "UP":
                    kbUP = 0
                Case "DOWN":
                    kbDOWN = 0
                Case "ESC":
                    End()
            EndSwitch
    ;Switch for Handler Func
    EndSwitch
EndFunction


SetInterval(1,p_mainloop,40)
InstallEventHandler({OnRawKeyDown = p_HandlerFunc, OnRawKeyUp = p_HandlerFunc})

Repeat
  WaitEvent
Forever  
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Correct Menu Nav System

Post by amyren »

I have not changed so much, but I did try to clean up a few lines not needed. Also removed the setinterval call and let the menu be handled by the eventhandler instead.

Code: Select all

@DISPLAY {width = 320, height = 240, ScaleMode = #SCALEMODE_AUTO, ScaleWidth = #NATIVE, ScaleHeight = #NATIVE}
NUMBER = 3
menuvar = 2

OpenMusic(1,"pdtraining.mod")
LoadBrush(1,"pd.jpeg",{scalewidth = 320, scaleheight = 240})
LoadSample(1,"menu.iff")
BlurBrush(1,NUMBER)
BrushToBGPic(1,1)
PlayMusic(1)

Function p_render()
	SetFont(#SANS, 12)
	CreateBrush(10,160,20,$2F52C9,{AlphaTransparency = True})
	CreateTextObject(1,"Small but Perfect Menu",{ALIGN = #LEFT,COLOUR = #WHITE})
	CreateBrush(11,160,140,$0E204A,{AlphaTransparency = True})
	SetFont(#MONOSPACE, 15)
	
	If menuvar = 2
	CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #RED})
	Else
	CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #WHITE})
	EndIf
	
	If menuvar = 3
	CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #RED})
	Else
	CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #WHITE})
	EndIf
	
	If menuvar = 4
	CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #RED})
	Else
	CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #WHITE})
	EndIf
	
	If menuvar = 5
	CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #RED})
	Else
	CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #WHITE})
	EndIf
	
	If menuvar = 6
	CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #RED})
	Else
	CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #WHITE})
	EndIf
	BeginRefresh()
	Cls()
	DisplayBGPic(1)
	DisplayBrush(10,80,20,{transparency = "25%"})
	DisplayTextObject(1,100,22)
	DisplayBrush(11,80,40,{transparency = "50%"})
	Global k = 0
	For i = 2 To 6 Step 1
	DisplayTextObject(i,120,48+k)
	If i = 5
	    k = k + 25
	    Else
	k = k + 25
	EndIf
	Next
	EndRefresh()
EndFunction


Function p_logic()
    If kbUP = 1
        If menuvar > 2
                PlaySample(1)
                menuvar = menuvar - 1
        EndIf
	kbUP = 0
    EndIf

    If kbDOWN = 1
        If menuvar < 6
                PlaySample(1)
                menuvar = menuvar + 1
        EndIf
	kbDOWN = 0
    EndIf
EndFunction

Function p_mainloop()
    p_logic()
    p_render()
EndFunction


Function p_HandlerFunc(msg)
    ;SWITCH FOR HANDLER FUNC
    Switch(msg.action)
        Case "OnRawKeyDown":
            Switch UpperStr(msg.key)
            ;Movement Flags Down
                Case "UP":
                    kbUP = 1
                Case "DOWN":
                    kbDOWN = 1
                Case "ESC":
                    End()
            EndSwitch
    EndSwitch
    p_mainloop
EndFunction

p_render() ;run once on startup

InstallEventHandler({OnRawKeyDown = p_HandlerFunc})

Repeat
  WaitEvent
Forever  
dewindatws
Posts: 12
Joined: Wed Sep 06, 2023 8:54 pm
Location: Wales
Contact:

Re: Correct Menu Nav System

Post by dewindatws »

Thank you very much!

I was wondering, whether a switch case would be better than a bunch of IF statements for the menu.
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Correct Menu Nav System

Post by amyren »

dewindatws wrote: Tue Oct 31, 2023 2:29 am Thank you very much!

I was wondering, whether a switch case would be better than a bunch of IF statements for the menu.
You could use a switch case, but since you also have the ELSE option for your IF's you probably need to have two swicth cases.
Here is a switch example.
I also moved the content of p_logic into the p_Handlerfunc and removed the p_Mainloop since all it did was to call the p_render function.

Code: Select all

@DISPLAY {width = 320, height = 240, ScaleMode = #SCALEMODE_AUTO, ScaleWidth = #NATIVE, ScaleHeight = #NATIVE}
NUMBER = 3
menuvar = 2

OpenMusic(1,"pdtraining.mod")
LoadBrush(1,"pd.jpeg",{scalewidth = 320, scaleheight = 240})
LoadSample(1,"menu.iff")
BlurBrush(1,NUMBER)
BrushToBGPic(1,1)
PlayMusic(1)

CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #WHITE})
CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #WHITE})
CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #WHITE})
CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #WHITE})
CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #WHITE})


Function p_render()
	SetFont(#SANS, 12)
	CreateBrush(10,160,20,$2F52C9,{AlphaTransparency = True})
	CreateTextObject(1,"Small but Perfect Menu",{ALIGN = #LEFT,COLOUR = #WHITE})
	CreateBrush(11,160,140,$0E204A,{AlphaTransparency = True})
	SetFont(#MONOSPACE, 15)
	
	Switch menuvar
		Case 2:
			CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #RED})
		Case 3:
			CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #RED})
		Case 4:
			CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #RED})
		Case 5:
			CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #RED})
		Case 6:
			CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #RED})
	EndSwitch
	
	Switch oldmenuvar
		Case 2:
			CreateTextObject(2,"Single Player",{ALIGN = #CENTER,COLOR = #WHITE})
		Case 3:
			CreateTextObject(3,"Multi-Player",{ALIGN = #CENTER,COLOR = #WHITE})
		Case 4:
			CreateTextObject(4,"Training",{ALIGN = #CENTER,COLOR = #WHITE})
		Case 5:
			CreateTextObject(5,"Options",{ALIGN = #CENTER,COLOR = #WHITE})
		Case 6:	
			CreateTextObject(6,"Quit",{ALIGN = #CENTER,COLOR = #WHITE})
	EndSwitch
	
	BeginRefresh()
	Cls()
	DisplayBGPic(1)
	DisplayBrush(10,80,20,{transparency = "25%"})
	DisplayTextObject(1,100,22)
	DisplayBrush(11,80,40,{transparency = "50%"})
	Global k = 0
	For i = 2 To 6 Step 1
		DisplayTextObject(i,120,48+k)
		If i = 5
		    k = k + 25
		Else
		    k = k + 25
		EndIf
	Next
	EndRefresh()
EndFunction

Function p_HandlerFunc(msg)
    ;SWITCH FOR HANDLER FUNC
    Switch(msg.action)
	Case "OnRawKeyDown":
	    Switch UpperStr(msg.key)
	    ;Movement Flags Down
		Case "UP":
			If menuvar > 2
				PlaySample(1)
				oldmenuvar = menuvar
				menuvar = menuvar - 1
			EndIf
		Case "DOWN":
			If menuvar < 6
				PlaySample(1)
				oldmenuvar = menuvar
				menuvar = menuvar + 1
			EndIf
		Case "ESC":
		    End()
	    EndSwitch
    EndSwitch
    p_render
EndFunction

p_render() ;run once on startup

InstallEventHandler({OnRawKeyDown = p_HandlerFunc})

Repeat
  WaitEvent
Forever  
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Correct Menu Nav System

Post by jPV »

Here are my comments, observations, and suggestions:

1) The program makes makes constant CPU load even when idling. On my Mac mini CPU usage is 100% all the time when just standing in the menu, which is not acceptable IMHO. Even the mouse pointer movement becomes jittery because of this. The heavy CPU load is because you update the display 25 times per second with a scaled display. Solution would be to use graphics that don't need to be scaled, and/or just update the display only when something happens. I'd suggest at least the latter with the event based code, then it will make zero load when idling.

2) If the NUMBER variable in the line 2 isn't going to be dynamic (you only set it once), it would be better make it constant, and maybe with name that indicates the relation: Const #BLUR = 3

3) In p_render() you create all the brushes over and over again in 25 times per second, which is very wasteful. I would suggest pre-rendering them just once. Or optimise amount of needed rendering.

4) You also draw some background things there. It would be more efficient to create the full background as a BGPic initially. And why to use separate brushes, draw boxes directly over the bg.

5) In p_render() you also have multiple "If" statements, when there isn't need to go through them all. A better structure for this would be more optimal. There are also many similar looking lines, which aren't harmful for the performance, but just make the code longer.

6) It's enough to set the BGPic once, not everytime p_render() is called (line 50). Move DisplayBGPic() up where you create the BGPic.

7) All your variables are global, which should be avoided as far as you can. It's inefficient to use global variables, and it's also difficult to keep count about variable names if they all are global... you'll get into trouble sooner or later with them (using same variable names accidently will make unexpected things etc). In an optimal program you don't have any global variables :) Use function arguments and return values to deliver data, and maybe name the remaining globals so that you recognize them for sure (I've started to add "g_" in front of globals myself). In Hollywood/Lua variables must be declared as Local or otherwise they become Global. This is opposite to, for example, Python, so it's important to notice how each language works regarding these. Read this carefully: https://www.hollywood-mal.com/docs/html ... cals_.html

8) p_logic() is full of global variables when they could be provided as arguments just fine. It is also called 25 times per second, but why just don't call it when an actual key press happens?

9) p_HandlerFunc() has a clumsy solution which results multiple key presses too easily. Why just don't listen for key up events? I think it'd be enough for a menu like this. Then user gets into prev/next menu item without accidently moving too many items at once. Contents of p_logic() could be implemented here too, but if you want to keep it separated, just call the function directly from here.


Ok, I started to modify your code, but it got out of hand and it doesn't resemble your version that much anymore :D But I'll show it anyway if you want to see a different perspective. I don't know if those menu tables are the best solution, I didn't think them through yet, just tried to expand the program to handle different menus too... I guess all these should be planned better before coding, but then I don't know your final goals either. In any case I try to pre-render as much as possible and then only render things that have actually changed when user presses a key, which means two text lines to different colors. The Options submenu also works in this example.

Code: Select all

@DISPLAY {width = 320, height = 240, ScaleMode = #SCALEMODE_AUTO, ScaleWidth = #NATIVE, ScaleHeight = #NATIVE}

Const #BLUR = 3

g_menu = {
    main = {
        "Single Player",
        "Multi-Player",
        "Training",
        "Options",
        "Quit"
    },
    options = {
        "Option 1",
        "Option 2",
        "Back"
    },
    active = "main", ; to store which (sub)menu is active
    item = 0         ; to store which item is selected in the menu
}

OpenMusic(1,"pdtraining.mod")
LoadSample(1,"menu.iff")
PlayMusic(1)

Function p_InitBG(file$)
    LoadBrush(1,file$,{scalewidth = 320, scaleheight = 240})
    BlurBrush(1,#BLUR)

    ; Draw extra decoration directly into the brush before converting it to a BGPic
    SelectBrush(1)
    SetFillStyle(#FILLCOLOR)
    Box(80,20,160,20,$2F52C9,{Transparency = "25%"})
    Box(80,40,160,140,$0E204A,{Transparency = "50%"})
    SetFont(#SANS, 12)
    CreateTextObject(1,"Small but Perfect Menu",{ALIGN = #LEFT,COLOUR = #WHITE})
    DisplayTextObject(1,100,22)
    EndSelect

    BrushToBGPic(1,1)
    DisplayBGPic(1)

    ; Free resources that won't be needed anymore, to save the memory
    FreeBrush(1)
    FreeTextObject(1)
EndFunction


Function p_InitMenu(menu$)
    g_menu.active = menu$
    g_menu.item = 0
    BeginRefresh()
    Cls()
    ; Render all texts in the selected menu, selected with red
    For Local i = 0 To ListItems(g_menu[menu$]) - 1
        If g_menu.item = i Then p_Render(i, True) Else p_Render(i)
    Next
    EndRefresh()
EndFunction


Function p_Render(item, selected)
    Local table = g_menu[g_menu.active]
    SetFont(#MONOSPACE, 15)
    CreateTextObject(1, table[item], {ALIGN = #CENTER, COLOR = IIf(selected, #RED, #WHITE)})
    DisplayTextObject(1, 120, 48 + 25*item)
    FreeTextObject(1) ; Object isn't needed anymore
EndFunction


Function p_Logic(direction)
    Local olditem = g_menu.item

    ; Add the direction value to the current item number, but limit the new item value between 0
    ; and amount of menu items in the currently active menu
    g_menu.item = Limit(g_menu.item + direction, 0, ListItems(g_menu[g_menu.active]) - 1)

    ; If item was changed, do things, otherwise let everything be like they were
    If g_menu.item <> olditem
        PlaySample(1)
        BeginRefresh()
        ; We don't need to clear the whole screen and re-draw everything, it's enough just
        ; render the changed texts
        p_Render(olditem, False)     ; Render the old item back to white
        p_Render(g_menu.item, True)  ; Render the new selected item to red
        EndRefresh()
    EndIf
EndFunction


Function p_MenuSelected()
    Switch g_menu.active
    Case "main":
        Switch g_menu.item
        Case 3:
            p_InitMenu("options")
        Case 4:
            End
        EndSwitch
    Case "options":
        Switch g_menu.item
        Case 2:
            p_InitMenu("main")
        EndSwitch
    EndSwitch
EndFunction


Function p_HandlerFunc(msg)
    Switch(msg.action)
        Case "OnRawKeyUp":
            Switch UpperStr(msg.key)
                Case "UP":
                    p_Logic(-1)
                Case "DOWN":
                    p_Logic(1)
                Case "RETURN":
                    p_MenuSelected()
                Case "ESC":
                    End()
            EndSwitch
    EndSwitch
EndFunction

p_InitBG("pd.jpeg")
p_InitMenu("main")

InstallEventHandler({OnRawKeyUp = p_HandlerFunc})

Repeat
  WaitEvent
Forever  
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Correct Menu Nav System

Post by amyren »

jPV wrote: Tue Oct 31, 2023 1:11 pm Here are my comments, observations, and suggestions:

1) The program makes makes constant CPU load even when idling. On my Mac mini CPU usage is 100% all the time when just standing in the menu, which is not acceptable IMHO. Even the mouse pointer movement becomes jittery because of this. The heavy CPU load is because you update the display 25 times per second with a scaled display. Solution would be to use graphics that don't need to be scaled, and/or just update the display only when something happens. I'd suggest at least the latter with the event based code, then it will make zero load when idling.
Good points.
For point 1 I hope you are refering to the code from the first post, as I think I did adress that in my reply by removing the setinterval and use eventhandler instead.

The downside of testing the scripts on even a modestly specced windows laptop is that the CPU load rarely shows any signs of having heavy load, so that bad coding practice is harder to spot. Just tried with the inbuilt windows cpu monitor and running all the variants in of the script in this thread and can not see any significant load difference between them. Opning a drawer with fileexplorer or a new tab in Chrome affects the cpu load way more.
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Correct Menu Nav System

Post by jPV »

amyren wrote: Thu Nov 02, 2023 12:40 pm Good points.
For point 1 I hope you are refering to the code from the first post, as I think I did adress that in my reply by removing the setinterval and use eventhandler instead.
Yeah, I based my answer to the original code, should have mentioned that.

The downside of testing the scripts on even a modestly specced windows laptop is that the CPU load rarely shows any signs of having heavy load, so that bad coding practice is harder to spot. Just tried with the inbuilt windows cpu monitor and running all the variants in of the script in this thread and can not see any significant load difference between them. Opning a drawer with fileexplorer or a new tab in Chrome affects the cpu load way more.
It's a very unfortunate loop in the world... when processing power increases, coders get lazier or more ignorant about efficient coding. And it wouldn't even be that difficult to make some basic planning about efficiency, it's quite logical if you give any thought to it, but why to do that when there's enough powerrrr in the latest hardware :/ For example, some might think G4 CPUs being slow nowadays, but they're still quite beasts crunching numbers and should be capable of doing much more than they can do with today's software... they should handle a simple game menu at least (no offence to OP, learning is still learning, and we're trying to teach as much as we can/know) ;)

It's a shame that older machines could still run all kinds of things very well if the coding wouldn't get sloppier all the time. I bet there's also a huge amount of wasted electricity and shorter battery lives in the world just because wasteful coding practises, so I would say that optimizing would still have its place in the world :)

In any case I still do some timing tests with my Hollywood programs even if I don't see any speed differences by eyes. Do some StartTimer() and GetTimer() around any heavier code blocks or functions, and try to get them more optimal.
dewindatws
Posts: 12
Joined: Wed Sep 06, 2023 8:54 pm
Location: Wales
Contact:

Re: Correct Menu Nav System

Post by dewindatws »

Firstly, I would like to thank you for giving me a lot of advice on how to improve my code, I am new to programming and so I am constantly learning. Both of your feedbacks has been useful.

However, I do not appericate some of your remarks.
jPV wrote: Thu Nov 02, 2023 3:23 pm coders get lazier or more ignorant about efficient coding. And it wouldn't even be that difficult to make some basic planning about efficiency, it's quite logical if you give any thought to it,
I am NOT lazy or ignorant about my code, I am a beginner as it was clear posting in the newbie questions, and to state it's not difficult to make some basic planning and how logical it is, was unkind and rude. We ALL have to start somewhere and there is no reason to be so discouraging about someone's effort and genuine questions on a beginners forum post.

I actually coded this on my iBook G4 running morphos and other than the multiple key presses glitch, it did not run jittery on my machine like you said, I am acutely aware of the speed of these chips and about how efficiency is key to getting the most out of this hardware, but this is why i am asking for advice on improvement, not to be indirectly called lazy, ignorant and illogical..

Alys
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Correct Menu Nav System

Post by jPV »

dewindatws wrote: Sun Nov 12, 2023 8:57 pm I am NOT lazy or ignorant about my code, I am a beginner as it was clear posting in the newbie questions, and to state it's not difficult to make some basic planning and how logical it is, was unkind and rude. We ALL have to start somewhere and there is no reason to be so discouraging about someone's effort and genuine questions on a beginners forum post.
I'm sorry you took it personally, it wasn't my intention at all.

I was replying to amyren's comment about bad coding practices not showing on modern hardware, which triggered an old grump in me to give a rant about the generic situation that's been present for a long time, especially since late 90s when computers got more common and processing power skyrocketed.

I tried to mention that this isn't aimed at You (OP/original poster) or any other beginners, but maybe I wasn't clear enough or it's a language barrier with my Finglish. I'm very sorry about it.

I was targetting my rant against to so-called professional coders, who only do it for the money and don't care about the result until it works on their cutting edge target hardware. Who just take the shortest route to get it done in minimum time by copy&pasting non-optimal code or stacking layers of libraries without trying to code anything themselves. Or coders who pretend to be professionals without actually knowing their stuff, but still spreading bad habits to others. This feeds the loop that users have to upgrade their hardware more often and then there's more processing power to waste by, let's say, lazy or ignorant coders again :)

This is especially visible in the web world nowadays. First, there are huge bloated browsers and web standards, which could be optimized in way better ways. For example, a well-known browser engine re-scales all images on a web page everytime the page is scrolled for even one pixel... why aren't these cached? No wonder it gets really jerky on older machines. And another things is Javascript etc. code that runs on top of the browser. There's so much bad code around which ignorant developers then stack over each other. Recently I came up with a public example code of a countdown clock that showed how many seconds there are left to a certain date... and it refreshed the graphics on the page 1000 times per second which made my G4 to choke. I made just one small change to the script to let it update more reasonable rate and then it ran just fine, but on how many pages this example code has already been copy&pasted and then just tell that old computers are useless. Makes me a bit angry and can lead to random rants ;)

But it's how the world runs... and it's easy to pick bad practises. I'm just a bit eager to tell people to pay attention to these kinds of things if we could make even a small change in the situation.

I actually coded this on my iBook G4 running morphos and other than the multiple key presses glitch, it did not run jittery on my machine like you said, I am acutely aware of the speed of these chips and about how efficiency is key to getting the most out of this hardware, but this is why i am asking for advice on improvement, not to be indirectly called lazy, ignorant and illogical..
One more tip on MorphOS is to have the CPU meter screenbar module enabled, it reveals the situations where CPU is, or has been, on maximum load. Of course it can't be avoided when there's lots of action, but would be nice that it would stay lower when the program/user isn't doing anything in practise.

As said, I wasn't directing my rant against you, and definitely not calling you anything directly or indirectly. And if you haven't learnt to think about these things yet, it doesn't mean that you'd be illogical or anything. I was just saying that when anyone is aware of these things, it's quite logical to make some basic optimizing if you just keep that in mind, but why on earth even those professional coders don't do it always?

I hope you keep learning and continue asking questions here, there is no such thing as a stupid question as they say. We're happy to help how we can, and it's a pleasure to get anyone to improve their coding skills. And learning never ends, I'm still learning better ways to code myself all the time too... I should re-write almost all my previous programs with the current knowledge :P So I'm happy to give at least some tips so that beginners wouldn't need to do all the same mistakes I've made :)
dewindatws
Posts: 12
Joined: Wed Sep 06, 2023 8:54 pm
Location: Wales
Contact:

Re: Correct Menu Nav System

Post by dewindatws »

Thank you. I would like to apologise for misinterpreting what you wrote. I now see that it wasn’t directed at anyone here, that was my mistake.

Sometimes I struggle with reading social situations due to my autism, which isn’t an excuse but I hope to give reason to my actions.

I agree with you that overly bloated code is prevalent in modern computing and we should not need to upgrade our systems as much as we do now. A modestly spec’d computer from 2010 could more than happily complete office tasks and light gaming if bloat was kept to a minimal.

I’m very grateful that you encourage me to continue to ask questions here, as I did feel awkward after responding how I did, your kindness is very appreciated.

- Alys
Post Reply