#Hey anyone would like to look into this small script?
9 messages · Page 1 of 1 (latest)
yes it's look good,
like this you defined all your flags one time in your map and you made an init for all you flags once with the initFlags function
It could be improve again i think but it's better than the switch case with all the flags 😉
i improved a little more. lil over engineering i think haha
if you have any suggestions do tell
Hey,
Sorry for the late, I was in Hollydays.
First when you have a ptn, you must check if it's not nil (or nil) before to used it.
For exemple here :
// displayMessages checks the flags and prints the message.
func displayMessages() bool {
displayed := false
for _, v := range flags {
// If flag is nil, you will trigger a nil pointer
if *v.flag {
colourize(v.colour, v.message)
displayed = true
}
}
return displayed
}
I suggest this:
if v.flag != nil && *v.flag {
colourize(v.colour, v.message)
displayed = true
}
And, it's pity to not used the power of a map, if possible it could be interesting to not iterate over the map and to call directly the right index.
Let me know if you need help for the changes
hey if im not iterating over map how can i colourize all the items in map?
Yes you must iterating to initialize but when you want to call the func displayMessage you can use a key.
I will look on your file searcher
thanks!!
is your project on git ?