Path: chuka.playstation.co.uk!news From: sosman@terratron.com (Steven Osman) Newsgroups: scee.yaroze.freetalk.english Subject: Re: Packet Explanation Date: Wed, 28 Nov 2001 05:08:20 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 35 Message-ID: <3c047011.1055088366@www.netyaroze-europe.com> References: <9tkp3s$dq91@www.netyaroze-europe.com> <9tlh4b$dq95@www.netyaroze-europe.com> <9tne1e$dq916@www.netyaroze-europe.com> <9u0lva$ogp5@www.netyaroze-europe.com> NNTP-Posting-Host: dsl092-099-074.nyc2.dsl.speakeasy.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Newsreader: Forte Agent 1.5/32.452 On Tue, 27 Nov 2001 18:27:37 -0000, "Martin Keates" wrote: >> how would i clear the screen, put the words " thanks for checking me oout" >> and then quit the program? > >Steven's state machine paradigm is a good way of working. >Rather than use switch/case though I'd use callback functions >(i.e. a variable that points to a function). So, you'd have a variable >for e.g. pad_func, display_func, compute_func or whatever and assign >different functions to them depending on the current state. Then >your main loop looks something like: >{ > (*pad_func)(); > (*compute_func)(); > (*display_func)(); >} > >Um - it's probably easier to look at an example. I seem to remember >nicking this idea off Alex so look at Super Bub source code. Sure, that works great. It does confuse people sometimes though... I think the code you put up there declares variables pad_func, compute_func and display_func. To call them you'd just use pad_func() I also think that an implementation like this is a little bit hard to read, but definitely faster than using switch statements. You have to dig into the structure that defines the functions (assuming you assign a structure that has pad, display and compute functions for each state) to find out exactly where the code is going. Steven p.s. Don't get me wrong... I like it nonetheless...