Computer Science Canada

better way to do this?

Author:  unknowngiver [ Thu May 25, 2006 4:35 pm ]
Post subject:  better way to do this?

Hey
is there a better way to do this?
i have a navigation bar and i want to check what button is clicked and then display that stuff
this is wt my teacher told me to do but i dont like it..as when i have more buttons it will be really crappy

code:

if page_main = true then

    GameServer.main_content (serverAddress + "maincontent.txt")
end if

loop

    if page_reg = true then
        cls
        render.bg
        GameServer.reg (serverAddress + "register.php")
        exit
    end if

end loop

that is to check what page is clicked and then to display that content
and then i have to do this everytime someone clicks a button

code:

                page_main := false
                page_reg := true

thats if the registertaion button is clicked
but when i have alot of buttons i will have a HUGE program
since i will have to define everything false n only the button that is clicked true for every button..and so on...is there is a better way of doing this? both checking what page is on and also putting it on the screen/
thanks

Author:  Remm [ Thu May 25, 2006 6:24 pm ]
Post subject: 

Erm, so you mean like when you click a button, what code should be used to go to a different page? / how to manage it?

Author:  Tony [ Thu May 25, 2006 6:42 pm ]
Post subject: 

you could have an array of boolean values. This way you can reset the entire group to false inside a forloop, and then use index to set the flags/buttons you want to true.

Author:  unknowngiver [ Thu May 25, 2006 7:19 pm ]
Post subject: 

Tony: i understood the array of boolean part...but not the index part...can u please explain it? maybe give an example or something
thanks Very Happy

Author:  unknowngiver [ Mon May 29, 2006 9:49 am ]
Post subject: 

still waiting

Author:  wtd [ Mon May 29, 2006 12:35 pm ]
Post subject: 

A small note:

code:
if page_main = true then


Is exactly the same as:

code:
if page_main then


You should use words like "is" in boolean variable names.


: