Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP]+[Matrix1Utils] Event System

Author
Message
DigitalFury
13
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 1st Dec 2010 20:37 Edited at: 2nd Dec 2010 03:07
I worked on a neat way to organize functions by how they are used. Setup function are called before the do loop. Loop functions are called inside the loop. Close function are called when the app closes. Simple but very helpful!

Please read everything because there is a lot to this function system.

How To Use:

If you need to setup something before entering the loop then add "Setup_" or "BeforeLoop_" in the Function's Name

Setup Functions:
Function Setup_()
Or
Function BeforeLoop_()

Some Functions have a setup order. If you need to have certain functions setup first then add:
` "SetupFirst_" Or "SetupSecond_" Or "SetupThird_" Or "SetupForth_" Or ... Or "SetupNineth_"

If you have a setup function that does some thing only once then use this code:



Loop Functions:
If you have a function to run within the loop then add "Loop_" Or "Step_" in the function's name

Function Loop_()
Or
Function Step_()

Close Functions:
If you need to save or delete something before closing then add "Save_" Or "OnClose_" Or "Closing_" in the function's name

Function Save_()
Or
Function OnClose_()
Or
Function Closing_()

Full Example:
How it works: Calls Setup(). If File Exists "File.dat" then it has been setup already and IsSetup = 1. SetupFirst_DoStuff is called first and creates a file if IsSetup = false. SetupNinth_DoStuff is called because it is the next function to be called. (I didn't add 2-8) Loop_PrintStuff will print a random number repeativly. OnClose_DoSomething is called when you press the escape key.



Example:
Call Setup functions will get everything going
If escape key = 1 then run all the close/save functions


Setup:
IsSetup: This is a variable you can use to test if everything is initially setup. This could be making a few files or something like that. Perform a quick check like for example if a those file exist and set to IsSetup = true if they exist.


Call Functions:
I don't really want to get into explaining how this works. It is kinda straight forward how it works. An algorithm to check if the first part of the function name is equal to some preset name. If so then call the function. Not much too it. Just a bit of a lengthy algorithm.

CallSetupFunctions()


CallLoopFunctions()


CallCloseFunctions()


This snippet is used in my project Zombie Project: Early WIP.

Any comments, questions, or bugs let me know. Don't forget to credit me if you use any of my code.

DigitalFury

Login to post a reply

Server time is: 2024-03-29 13:29:20
Your offset time is: 2024-03-29 13:29:20