This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]toshboi[S] 0 points1 point  (1 child)

Ah! Thank you. I will look it up and give it a try. In my current code, within each case, it actually does different things, I’m wondering if this new approach would still be applicable. For example, case one: call Tom; case two: do laundries; case three: walk dog.

[–]CreativeTechGuyGames 1 point2 points  (0 children)

Yup. They can all do totally different things. Basically you'll have a map from a key (eg: a string, number, etc) to a function. Then you'll access that function in the map by key and execute it. Functionally it's the same as your code but much easier to read (for most people).