Jump to content
MakeWebGames

how to make navigation links flexible


ags_cs4

Recommended Posts

today i wanted to change the stupid html mainmenu to somthing good and easy to edit any time

so the idea i got was to use multidimensional arrays for fast edit and flexibility.

want to learn more? read this topic

screenshot: 

image.png.18ad5faa4a497793c43ba691e07e287b.png

 

Lets get started

in my code i wanted to get flexible links so i can show them when you are in jail or hospital or donators or no mater what condition is with small edits , so in my array i added 2 key one for hospital and one for jail, and the array looks like this

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

so as you can see we have 6 keys 4 of them are for the link html code and the last 2 are our conditions

true mean that the link show, and false mean the link is hidden on that condition

so lest keep going

the idea was so i can show 3 sections 2 are always shown and 1 for only doantors only

so i made an array like this: 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

we can see we have 3 keys , one for the name of the section, one for our condition which is donator, the last is the array of our links that we worked on them before

now lets go to the loop to show our sections

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

so we stored our multidimensional array in a variable named $navigations and we lopped it using foreach
we added a condition for 'donatordays' if its true it wont show that section.
inside the first foreach we added another foreach to loop our list of links using our 'links' key $navigation['links'] from the first foreach.
as you can see we have 2 condition 1 for jail which is big than the current timestamp(my game use timestamp not minutes crons) while the value from the array key "jail" = false, the same thing for hospital.
while we have nothing printed inside that if/else of both condition of jail/hospital so that it wont show any link when the condition is true.

a full code if you get lost in the way ? 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.


in the end this way will make it east to add condition to each link or section with out having to make the html code more confusing by adding more if/else statments

PS: this my first time writing an article in english so bear with me 

  • Like 4
Link to comment
Share on other sites

  • 3 weeks later...

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

A little old but this is kind of what I did. It is similar to what you have but I think this may just be a little bit more flexible for the most part and will pretty much reduce any potential nested ifs

Edited by KyleMassacre
  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...